From 80edcffbfe140a6d19c65deca24e1ba1c0f49b99 Mon Sep 17 00:00:00 2001 From: Devendra Date: Mon, 24 Mar 2014 19:17:48 +0530 Subject: support for python3 --- python/examples/subscribe-example.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'python/examples/subscribe-example.py') diff --git a/python/examples/subscribe-example.py b/python/examples/subscribe-example.py index 14a43d9..a67a08f 100755 --- a/python/examples/subscribe-example.py +++ b/python/examples/subscribe-example.py @@ -1,5 +1,6 @@ import sys -sys.path.append('../') +sys.path.append('..') +sys.path.append('.') import threading import time import random @@ -59,7 +60,7 @@ publish() print("waiting for subscribes and presence") pres_thread.join() -print pubnub.here_now({'channel':channel}) +print(pubnub.here_now({'channel':channel})) sub_thread.join() -- cgit v1.2.3 From 09cd0c015ae276aa849297a6a976065b2b3f247b Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 23 Apr 2014 14:03:13 +0530 Subject: modifying code for pep 8 compliance --- python/examples/subscribe-example.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'python/examples/subscribe-example.py') diff --git a/python/examples/subscribe-example.py b/python/examples/subscribe-example.py index a67a08f..0a18899 100755 --- a/python/examples/subscribe-example.py +++ b/python/examples/subscribe-example.py @@ -8,48 +8,55 @@ import string from Pubnub import Pubnub ## Initiate Class -pubnub = Pubnub( 'demo', 'demo', None, False ) +pubnub = Pubnub('demo', 'demo', None, False) -print("My UUID is: "+pubnub.uuid) +print("My UUID is: " + pubnub.uuid) -channel = ''.join(random.choice(string.ascii_letters + string.digits) for x in range(20)) +channel = ''.join( + random.choice(string.ascii_letters + string.digits) for x in range(20)) ## Subscribe Example -def receive(message) : + + +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 + 'channel': channel, + 'callback': receive }) + def presence(): print("Listening for presence events on '%s' channel..." % channel) pubnub.presence({ - 'channel' : channel, - 'callback' : pres_event + 'channel': channel, + 'callback': pres_event }) + def publish(): print("Publishing a test message on '%s' channel..." % channel) pubnub.publish({ - 'channel' : channel, - 'message' : { 'text':'foo bar' } + 'channel': channel, + 'message': {'text': 'foo bar'} }) pres_thread = threading.Thread(target=presence) -pres_thread.daemon=True +pres_thread.daemon = True pres_thread.start() sub_thread = threading.Thread(target=subscribe) -sub_thread.daemon=True +sub_thread.daemon = True sub_thread.start() time.sleep(3) @@ -60,7 +67,6 @@ publish() print("waiting for subscribes and presence") pres_thread.join() -print(pubnub.here_now({'channel':channel})) +print(pubnub.here_now({'channel': channel})) sub_thread.join() - -- cgit v1.2.3 From 93379625e26c98a8cfab72c106ae40819843f956 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 00:35:10 +0530 Subject: remove relative imports --- python/examples/subscribe-example.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'python/examples/subscribe-example.py') diff --git a/python/examples/subscribe-example.py b/python/examples/subscribe-example.py index 0a18899..0b1c949 100755 --- a/python/examples/subscribe-example.py +++ b/python/examples/subscribe-example.py @@ -1,6 +1,4 @@ import sys -sys.path.append('..') -sys.path.append('.') import threading import time import random -- cgit v1.2.3 From c98286f500b77dcf426367df0b688f536b77ea9b Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 01:33:45 +0530 Subject: fixing imports --- python/examples/subscribe-example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/examples/subscribe-example.py') diff --git a/python/examples/subscribe-example.py b/python/examples/subscribe-example.py index 0b1c949..9c16bbe 100755 --- a/python/examples/subscribe-example.py +++ b/python/examples/subscribe-example.py @@ -3,7 +3,7 @@ import threading import time import random import string -from Pubnub import Pubnub +from Pubnub import PubnubAsync as Pubnub ## Initiate Class pubnub = Pubnub('demo', 'demo', None, False) -- cgit v1.2.3 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/subscribe-example.py | 70 ------------------------------------ 1 file changed, 70 deletions(-) delete mode 100755 python/examples/subscribe-example.py (limited to 'python/examples/subscribe-example.py') 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() -- cgit v1.2.3