1 """ Watch for locevt and print them """
3 from configparser import ConfigParser
4 from datetime import datetime, timezone
5 from logging import getLogger
9 from .gps303proto import parse_message
10 from .zmsg import Bcast
12 log = getLogger("gps303/watch")
15 def runserver(conf: ConfigParser) -> None:
16 # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?!
17 zctx = zmq.Context() # type: ignore
18 zsub = zctx.socket(zmq.SUB) # type: ignore
19 zsub.connect(conf.get("collector", "publishurl"))
20 zsub.setsockopt(zmq.SUBSCRIBE, b"")
24 zmsg = Bcast(zsub.recv())
25 msg = parse_message(zmsg.packet, zmsg.is_incoming)
26 print("I" if zmsg.is_incoming else "O", zmsg.imei, msg)
27 except KeyboardInterrupt:
31 if __name__.endswith("__main__"):
32 runserver(common.init(log))