Skip to content

Instantly share code, notes, and snippets.

@stephenlb
Last active February 4, 2021 02:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenlb/33722e268b3f12c969d90f3ae40244fe to your computer and use it in GitHub Desktop.
Save stephenlb/33722e268b3f12c969d90f3ae40244fe to your computer and use it in GitHub Desktop.
USE THIS https://github.com/stephenlb/pubnub-python-docker - THE CODE BELOW IS FINE< BUT IF YOU WANT DOCKERFILE, USE REPO
import pubnub#pubnub==4.0.2
import time
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
pnconf = PNConfiguration()
pnconf.subscribe_key = "demo"
pnconf.publish_key = "demo"
pubnub = PubNub(pnconf)
def show(msg, stat):
if msg and stat: print( msg.timetoken, stat.status_code )
else : print( "Error", stat and stat.status_code )
while True:
pubnub.publish().channel("change_log").message("hello").async(show)
time.sleep(2)
import pubnub
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub, SubscribeListener
class DatabaseSync(SubscribeListener):
def message( self, pubnub, data ):
print( "Saving to Database: ", data.message )
pnconfig = PNConfiguration()
pnconfig.subscribe_key = 'demo'
pnconfig.publish_key = 'demo'
pubnub = PubNub(pnconfig)
pubnub.add_listener(DatabaseSync())
pubnub.subscribe().channels("change_log").execute()
@stephenlb
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment