example subscriber to live updates

play with blocking/unblocking connections to us-east-1.amazonaws.com and see msg count drop to zero/picking up again after unblocking
pull/2/head
Michael Haberler 2021-04-02 15:17:09 +02:00
rodzic ff447ac37a
commit 4a2f60d2da
1 zmienionych plików z 32 dodań i 0 usunięć

32
examples/live.py 100644
Wyświetl plik

@ -0,0 +1,32 @@
import json
import time
import sondehub
interval = 5
msgs = 0
elapsed = 0
starttime = 0
log = True
def on_msg(*args):
global msgs
msgs +=1
def on_connect(*args):
print("on_connect:", *args)
def on_disconnect(*args):
print("on_disconnect:", *args)
def on_log(*args):
if log:
print(f"on_log:", *args)
sh = sondehub.Stream(on_message=on_msg,
on_disconnect=on_disconnect,
on_log=on_log,
on_connect=on_connect);
while True:
time.sleep(interval)
print(f"tick {msgs=}")
msgs = 0