-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (24 loc) · 855 Bytes
/
test.py
File metadata and controls
31 lines (24 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import asyncio
import json
import socket
from delate import connection
async def main():
try:
while True:
try:
async with connection.Connection() as conn:
print("Connected")
async with connection.Subscription(
conn, ["timetable_8000261"]
) as sub:
async for msg in sub:
print(json.dumps(msg.content, indent=4, sort_keys=True))
await conn.close()
except socket.gaierror as e:
print(f"Connection failed: {e}")
print("Restarting ...")
await asyncio.sleep(5)
finally:
asyncio.get_event_loop().stop()
asyncio.get_event_loop().create_task(main())
asyncio.get_event_loop().run_forever()