javascript - Can we republish messages in PUBNUB -


i have situation can data python can publish via python. need visualize data need subscribe channel via javascript. visualization libaray c3.js takes data following format:

message: {       columns: [         ['x', volume],         ['y', timetamp]       ]     } 

to data in python difficult me. easier solution subscribe via javascript , again republish data desired format. question is, possible in pubnub if need publish data channel or same channel ok?

my python code is:

for each in data:     y = each.counter_volume     x = each.timestamp     pubnub.publish(channel='orbit_channel', message=y) 

my desired output is

    message: {              "columns": [    ["x", "2015-07-06t13:26:19", "2015-07-06t13:26:19","2015-07-06t13:26:19"],    ["y", 5000.0, 5000.0, 5000.0] ] } 

to data in python difficult me.

that format json , data can serialized pretty easy in python, try json module:

import json time import gmtime, strftime  = str(strftime("%y-%m-%dt%h:%m:%s", gmtime())) n = 5000.0  message = {"columns": [["x", now, now, now], ["y", n, n, n]]} print "message: " + json.dumps(message, indent=4, separators=(',', ': ')) 

output:

message: {     "columns": [         [             "x",             "2015-07-16t12:56:47",             "2015-07-16t12:56:47",             "2015-07-16t12:56:47"         ],         [             "y",             5000.0,             5000.0,             5000.0         ]     ] } 

maybe providing data in expected way easier work in js file?


Comments