In [39]:
from pubnub.pubnub import PubNub
from pubnub.pnconfiguration import PNConfiguration
import random
import time

In [28]:
publish_key='pub-c-60e2bc08-b809-4a24-8691-e59eda94e056'

In [29]:
subscribe_key='sub-c-ed47cf5a-4c02-11e7-a368-0619f8945a4f'

In [30]:
pnconfig = PNConfiguration()
pnconfig.subscribe_key = subscribe_key
pnconfig.publish_key = publish_key
pnconfig.ssl = False

In [31]:
p=PubNub(pnconfig)

In [32]:
p.subscribe().channels('Temperature').execute()

In [33]:
def publish_callback(result, status):
    print('It is successful!')
    # handle publish result, status always present, result if successful
    # status.isError to see if error happened

In [35]:
def send_message(message):
    p.publish().channel("Temperature").message(message).should_store(True).use_post(True).async(publish_callback)

In [62]:
p.publish().channel("Temperature").message('Null2').should_store(True).use_post(True).async(publish_callback)


Out[62]:
<pubnub.request_handlers.requests_handler.Call at 0x7f43580946d8>

In [60]:
for i in range(100):
    T=random.randint(0,100)
    t=time.strftime('%Y/%m/%d %H:%M:%S',time.localtime())
    send_message({t:T})
    time.sleep(1)
    print('%s:%d'%(t,T))


2017/06/08 15:21:35:11
2017/06/08 15:21:36:63
2017/06/08 15:21:37:88
2017/06/08 15:21:38:78
2017/06/08 15:21:39:5
2017/06/08 15:21:40:24
2017/06/08 15:21:41:77
2017/06/08 15:21:42:80
2017/06/08 15:21:43:89
2017/06/08 15:21:44:3
2017/06/08 15:21:45:38
2017/06/08 15:21:46:3
2017/06/08 15:21:47:78
2017/06/08 15:21:48:89
2017/06/08 15:21:49:86
2017/06/08 15:21:50:88
2017/06/08 15:21:51:21
2017/06/08 15:21:52:59
2017/06/08 15:21:53:64
2017/06/08 15:21:54:46
2017/06/08 15:21:55:89
2017/06/08 15:21:56:12
2017/06/08 15:21:57:35
2017/06/08 15:21:58:87
2017/06/08 15:21:59:24
2017/06/08 15:22:00:89
2017/06/08 15:22:01:17
2017/06/08 15:22:02:91
2017/06/08 15:22:03:94
2017/06/08 15:22:04:53
2017/06/08 15:22:05:75
2017/06/08 15:22:06:55
2017/06/08 15:22:07:88
2017/06/08 15:22:08:40
2017/06/08 15:22:09:0
2017/06/08 15:22:10:24
2017/06/08 15:22:11:37
2017/06/08 15:22:12:40
2017/06/08 15:22:13:70
2017/06/08 15:22:14:14
2017/06/08 15:22:15:42
2017/06/08 15:22:16:4
2017/06/08 15:22:17:64
2017/06/08 15:22:18:6
2017/06/08 15:22:19:0
2017/06/08 15:22:20:42
2017/06/08 15:22:21:25
2017/06/08 15:22:22:2
2017/06/08 15:22:23:29
2017/06/08 15:22:24:31
2017/06/08 15:22:25:87
2017/06/08 15:22:26:21
2017/06/08 15:22:27:98
2017/06/08 15:22:28:36
2017/06/08 15:22:29:5
2017/06/08 15:22:30:81
2017/06/08 15:22:31:29
2017/06/08 15:22:32:17
2017/06/08 15:22:33:55
2017/06/08 15:22:34:2
2017/06/08 15:22:35:63
2017/06/08 15:22:36:74
2017/06/08 15:22:37:91
2017/06/08 15:22:38:51
2017/06/08 15:22:39:95
2017/06/08 15:22:40:81
2017/06/08 15:22:41:3
2017/06/08 15:22:42:96
2017/06/08 15:22:44:70
2017/06/08 15:22:45:34
2017/06/08 15:22:46:71
2017/06/08 15:22:47:37
2017/06/08 15:22:48:2
2017/06/08 15:22:49:55
2017/06/08 15:22:50:7
2017/06/08 15:22:51:57
2017/06/08 15:22:52:3
2017/06/08 15:22:53:34
2017/06/08 15:22:54:51
2017/06/08 15:22:55:26
2017/06/08 15:22:56:35
2017/06/08 15:22:57:88
2017/06/08 15:22:58:52
2017/06/08 15:22:59:11
2017/06/08 15:23:00:60
2017/06/08 15:23:01:49
2017/06/08 15:23:02:51
2017/06/08 15:23:03:25
2017/06/08 15:23:04:75
2017/06/08 15:23:05:87
2017/06/08 15:23:06:64
2017/06/08 15:23:07:68
2017/06/08 15:23:08:76
2017/06/08 15:23:09:18
2017/06/08 15:23:10:8
2017/06/08 15:23:11:92
2017/06/08 15:23:12:47
2017/06/08 15:23:13:26
2017/06/08 15:23:14:67
2017/06/08 15:23:15:45

In [ ]: