Created
August 8, 2018 01:54
-
-
Save stephenlb/af711ec727def9930c55c0c2ff5164f2 to your computer and use it in GitHub Desktop.
Python Subscribe: Basic Worker. Super Simple
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 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