Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Subscribe: Basic Worker. Super Simple
import multiprocessing
import requests
SUB_KEY = 'demo'
CHANNELS = ['my_channel']
def main():
mp = multiprocessing.Process(target=subscriber)
mp.start()
mp.join()
def subscriber():
timetoken = '0' ## pointer to last message received
while True:
url = "/".join([
'https://ps.pubnub.com/subscribe'
, SUB_KEY
, ",".join(CHANNELS)
, '0'
, timetoken
])
print(url)
response = requests.get(url)
data = response.json()
messages = data[0]
timetoken = data[1]
print(data)
if __name__ == '__main__': main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.