Created
December 14, 2021 22:30
-
-
Save krsboone/4c5b22d0b42ad1f73e79b5dec1aea535 to your computer and use it in GitHub Desktop.
Crude subscribe loop. Returns message data that was received.
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 requests | |
import json | |
payload = {} | |
headers = {} | |
base_url = 'https://ps.pndsn.com/v2/subscribe/' | |
sub_key = 'sub-key' | |
channel = 'guide987' | |
p_uuid = '555serverUUID-PUB' | |
s_uuid = '555serverUUID-SUB' | |
cb = '0' | |
tt = '0' | |
init_url = base_url + sub_key + '/' + channel + '/' + cb + '?uuid=' + s_uuid + '&tt=' + tt | |
def empty_start(url): | |
response = requests.request("GET", url, headers=headers, data=payload) | |
j_data = json.loads(response.text) | |
if p_uuid in response.text: | |
print('Message Received:') | |
message = j_data['m'] | |
for items in message: | |
print(items['d']) | |
time_token = (j_data['t']['t']) | |
print('Time Token received: '+time_token) | |
return time_token | |
time_token = empty_start(init_url) | |
print('Starting Subscribe with valid Time Token:') | |
while True: | |
sub_url = base_url + sub_key + '/' + channel + '/' + cb + '?uuid=' + s_uuid + '&tt=' + time_token | |
time_token = empty_start(sub_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment