Skip to content

Instantly share code, notes, and snippets.

@krsboone
Created December 14, 2021 22:30
Show Gist options
  • Save krsboone/4c5b22d0b42ad1f73e79b5dec1aea535 to your computer and use it in GitHub Desktop.
Save krsboone/4c5b22d0b42ad1f73e79b5dec1aea535 to your computer and use it in GitHub Desktop.
Crude subscribe loop. Returns message data that was received.
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