Last active
February 4, 2021 02:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USE THIS https://github.com/stephenlb/pubnub-python-docker