import sys from Pubnub import Pubnub publish_key = 'pub-c-6c6b1294-7fdd-4f33-aec4-41217a6d0b6c' subscribe_key = 'sub-c-cf0e18e6-bd43-11e4-861a-0619f8945a4f' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) channel = 'my_channel' # Synchronous usage print pubnub.history(channel, count=10) # Asynchronous usage def callback(message): print(message) pubnub.history(channel, count=10, callback=callback, error=callback)
## Time Example ## ----------------------------------------------------------------------- def time_complete(timestamp): print(timestamp) pubnub.time({ 'callback' : time_complete }) ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- def history_complete(messages): print(messages) pubnub.history( { 'channel' : crazy, 'limit' : 10, 'callback' : history_complete }) ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- def publish_complete(info): print(info) pubnub.publish({ 'channel' : crazy, 'message' : "Hello World", 'callback' : publish_complete })
## ----------------------------------------------------------------------- def time_complete(timestamp): print(timestamp) pubnub.time({'callback': time_complete}) ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- def history_complete(messages): print(messages) pubnub.history({'channel': crazy, 'limit': 10, 'callback': history_complete}) ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- def publish_complete(info): print(info) pubnub.publish({ 'channel': crazy, 'message': "Hello World", 'callback': publish_complete })
else : print( 'FAIL: ' + name ) ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- publish_success = pubnub.publish({ 'channel' : crazy, 'message' : crazy }) test( publish_success[0] == 1, 'Publish First Message Success' ) ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- history = pubnub.history({ 'channel' : crazy, 'limit' : 1 }) test( history[0].encode('utf-8') == crazy, 'History Message: ' + history[0] ) test( len(history) == 1, 'History Message Count' ) ## ----------------------------------------------------------------------- ## PubNub Server Time Example ## ----------------------------------------------------------------------- timestamp = pubnub.time() test( timestamp > 0, 'PubNub Server Time: ' + str(timestamp) )
import sys sys.path.append('../') from Pubnub import Pubnub ## Initiat Class pubnub = Pubnub('demo', 'demo', None, False) ## History Example history = pubnub.history({'channel': 'hello_world', 'limit': 1}) print(history)
## Time Example ## ----------------------------------------------------------------------- def time_complete(timestamp): print(timestamp) pubnub.time({"callback": time_complete}) ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- def history_complete(messages): print(messages) pubnub.history({"channel": crazy, "limit": 10, "callback": history_complete}) ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- def publish_complete(info): print(info) pubnub.publish( { "channel": crazy, "message": {"one": "Hello World! --> ɂ顶@#$%^&*()!", "two": "hello2"}, "callback": publish_complete, } )
from Pubnub import Pubnub ## THIS BIT ALLOWS US TO USE "urlfetch" from GAE while running from ## Not needed in runtime from google.appengine.api import apiproxy_stub_map from google.appengine.api import urlfetch_stub # Create a stub map so we can build App Engine mock stubs. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Register App Engine mock stubs. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) ## ------------------------------------------------------------- ## Initiat Class pubnub = Pubnub( 'demo', 'demo', None, False ) ## History Example history = pubnub.history({ 'channel' : 'hello_world', 'limit' : 1 }) print(history)
import sys sys.path.append("../") from Pubnub import Pubnub ## Initiat Class pubnub = Pubnub("demo", "demo", None, False) ## History Example history = pubnub.history({"channel": "hello_world", "limit": 1}) print(history)
## http://www.pubnub.com/ import sys from Pubnub import Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) channel = 'a' # Synchronous usage print pubnub.history(channel, count=2) # Asynchronous usage def callback(message): print(message) pubnub.history(channel, count=2, callback=callback, error=callback)