From cf1021b3671fb7537ad7b3a4d577ef0fcace694a Mon Sep 17 00:00:00 2001 From: Devendra Date: Tue, 6 May 2014 16:43:09 +0530 Subject: modifying examples --- python/examples/here-now-example.py | 32 ----------------- python/examples/here-now.py | 36 +++++++++++++++++++ python/examples/history-example.py | 12 ------- python/examples/history.py | 34 ++++++++++++++++++ python/examples/publish-example.py | 44 ----------------------- python/examples/publish.py | 37 +++++++++++++++++++ python/examples/subscribe-example.py | 70 ------------------------------------ python/examples/subscribe.py | 46 ++++++++++++++++++++++++ 8 files changed, 153 insertions(+), 158 deletions(-) delete mode 100644 python/examples/here-now-example.py create mode 100644 python/examples/here-now.py delete mode 100755 python/examples/history-example.py create mode 100644 python/examples/history.py delete mode 100755 python/examples/publish-example.py create mode 100644 python/examples/publish.py delete mode 100755 python/examples/subscribe-example.py create mode 100644 python/examples/subscribe.py (limited to 'python/examples') diff --git a/python/examples/here-now-example.py b/python/examples/here-now-example.py deleted file mode 100644 index 0bc3015..0000000 --- a/python/examples/here-now-example.py +++ /dev/null @@ -1,32 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - - -import sys -from Pubnub import PubnubAsync as 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) -crazy = 'hello_world' - - -def print_cb(message): - print(message) - -pubnub.here_now({ - 'channel': crazy, - 'callback': print_cb -}) diff --git a/python/examples/here-now.py b/python/examples/here-now.py new file mode 100644 index 0000000..f573389 --- /dev/null +++ b/python/examples/here-now.py @@ -0,0 +1,36 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubAsync as 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 = 'hello_world' + + + +# Synchronous usage + +print pubnub.here_now(channel) + +# Asynchronous usage + +def callback(message): + print(message) + +pubnub.here_now(channel, callback=callback, error=callback) diff --git a/python/examples/history-example.py b/python/examples/history-example.py deleted file mode 100755 index 793c612..0000000 --- a/python/examples/history-example.py +++ /dev/null @@ -1,12 +0,0 @@ -import sys -from Pubnub import PubnubAsync as Pubnub - -## Initiat Class -pubnub = Pubnub('demo', 'demo', None, False) - -## History Example -history = pubnub.history({ - 'channel': 'hello_world', - 'limit': 1 -}) -print(history) diff --git a/python/examples/history.py b/python/examples/history.py new file mode 100644 index 0000000..3d6addf --- /dev/null +++ b/python/examples/history.py @@ -0,0 +1,34 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubAsync as 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) diff --git a/python/examples/publish-example.py b/python/examples/publish-example.py deleted file mode 100755 index 78b7f36..0000000 --- a/python/examples/publish-example.py +++ /dev/null @@ -1,44 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -import sys -from Pubnub import PubnubAsync as 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 '' # (Cipher key is Optional) -auth_key = len( - sys.argv) > 5 and sys.argv[4] or 'abcd' # (Cipher key is Optional) -ssl_on = len(sys.argv) > 6 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub( - publish_key, subscribe_key, secret_key, cipher_key, auth_key, ssl_on, pooling=True) -crazy = 'hello_world' - -## ----------------------------------------------------------------------- -## Publish Example -## ----------------------------------------------------------------------- - - -def publish_complete(info): - print(info) - - -def publish_error(info): - print('ERROR : ' + str(info)) - -import time -start = time.time() -for i in range(1,100): - print pubnub.publish(crazy, 'hello world-' + str(i)) -end = time.time() -print(end - start); diff --git a/python/examples/publish.py b/python/examples/publish.py new file mode 100644 index 0000000..029c17a --- /dev/null +++ b/python/examples/publish.py @@ -0,0 +1,37 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubAsync as 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 = 'hello_world' +message = 'Hello World !!!' + + + +# Synchronous usage + +print pubnub.publish(channel, message) + +# Asynchronous usage + +def callback(message): + print(message) + +pubnub.publish(channel, message, callback=callback, error=callback) diff --git a/python/examples/subscribe-example.py b/python/examples/subscribe-example.py deleted file mode 100755 index 9c16bbe..0000000 --- a/python/examples/subscribe-example.py +++ /dev/null @@ -1,70 +0,0 @@ -import sys -import threading -import time -import random -import string -from Pubnub import PubnubAsync as Pubnub - -## Initiate Class -pubnub = Pubnub('demo', 'demo', None, False) - -print("My UUID is: " + pubnub.uuid) - -channel = ''.join( - random.choice(string.ascii_letters + string.digits) for x in range(20)) - -## Subscribe Example - - -def receive(message): - print(message) - return False - - -def pres_event(message): - print(message) - return False - - -def subscribe(): - print("Listening for messages on '%s' channel..." % channel) - pubnub.subscribe({ - 'channel': channel, - 'callback': receive - }) - - -def presence(): - print("Listening for presence events on '%s' channel..." % channel) - pubnub.presence({ - 'channel': channel, - 'callback': pres_event - }) - - -def publish(): - print("Publishing a test message on '%s' channel..." % channel) - pubnub.publish({ - 'channel': channel, - 'message': {'text': 'foo bar'} - }) - -pres_thread = threading.Thread(target=presence) -pres_thread.daemon = True -pres_thread.start() - -sub_thread = threading.Thread(target=subscribe) -sub_thread.daemon = True -sub_thread.start() - -time.sleep(3) - -publish() - - -print("waiting for subscribes and presence") -pres_thread.join() - -print(pubnub.here_now({'channel': channel})) - -sub_thread.join() diff --git a/python/examples/subscribe.py b/python/examples/subscribe.py new file mode 100644 index 0000000..a410297 --- /dev/null +++ b/python/examples/subscribe.py @@ -0,0 +1,46 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubAsync as 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' + + + +# Asynchronous usage + +def callback(message, channel): + print(message) + +def error(message): + print("ERROR : " + str(message)) + +def connect(message): + print("CONNECTED") + +def reconnect(message): + print("RECONNECTED") + +def disconnect(message): + print("DISCONNECTED") + + +pubnub.subscribe(channel, callback=callback, error=callback, connect=connect, reconnect=reconnect, disconnect=disconnect) -- cgit v1.2.3