]> www.average.org Git - loctrkd.git/blob - gps303/watch.py
WIP retoure messaging
[loctrkd.git] / gps303 / watch.py
1 """ Watch for locevt and print them """
2
3 from datetime import datetime, timezone
4 from logging import getLogger
5 import zmq
6
7 from . import common
8 from .gps303proto import parse_message
9 from .zmsg import Bcast
10
11 log = getLogger("gps303/watch")
12
13
14 def runserver(conf):
15     zctx = zmq.Context()
16     zsub = zctx.socket(zmq.SUB)
17     zsub.connect(conf.get("collector", "publishurl"))
18     zsub.setsockopt(zmq.SUBSCRIBE, b"")
19
20     try:
21         while True:
22             zmsg = Bcast(zsub.recv())
23             msg = parse_message(zmsg.packet, zmsg.is_incoming)
24             print("I" if zmsg.is_incoming else "O", zmsg.imei, msg)
25     except KeyboardInterrupt:
26         pass
27
28
29 if __name__.endswith("__main__"):
30     runserver(common.init(log))