diff options
| author | Devendra | 2014-04-23 14:03:13 +0530 |
|---|---|---|
| committer | Devendra | 2014-04-23 14:03:13 +0530 |
| commit | 09cd0c015ae276aa849297a6a976065b2b3f247b (patch) | |
| tree | f1b253aa856e3a16e36eea9213857a33f6c35df4 /python/examples/subscribe-example.py | |
| parent | fdb46e56fa6794940f9fbe51a2863d58e927e655 (diff) | |
| download | pubnub-python-09cd0c015ae276aa849297a6a976065b2b3f247b.tar.bz2 | |
modifying code for pep 8 compliance
Diffstat (limited to 'python/examples/subscribe-example.py')
| -rwxr-xr-x | python/examples/subscribe-example.py | 34 |
1 files changed, 20 insertions, 14 deletions
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() - |
