Skip to content

Instantly share code, notes, and snippets.

@anovikov1984
Created February 1, 2017 18:09
Show Gist options
  • Save anovikov1984/559c2d1dba1ad5c0aa779454b2785501 to your computer and use it in GitHub Desktop.
Save anovikov1984/559c2d1dba1ad5c0aa779454b2785501 to your computer and use it in GitHub Desktop.
import os
import sys
import logging
import time
from pubnub.callbacks import SubscribeCallback
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
d = os.path.dirname
PUBNUB_ROOT = d(d(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(PUBNUB_ROOT)
import pubnub
pubnub.set_stream_logger('pubnub', logging.DEBUG, stream=sys.stdout)
class MyCallback(SubscribeCallback):
def presence(self, pubnub, presence):
pass
def message(self, pubnub, message):
print(message)
def status(self, pubnub, status):
pass
if __name__ == '__main__':
pnconf = PNConfiguration()
pnconf.subscribe_key = "demo"
pnconf.publish_key = "demo"
pubnub = PubNub(pnconf)
pubnub.add_listener(MyCallback())
pubnub.subscribe().channels("blah").execute()
# You need to wait for any subscribe callback on you own, for ex:
# time.sleep(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment