1 """ Watch for locevt and print them """
3 from configparser import ConfigParser
4 from datetime import datetime, timezone
5 from importlib import import_module
6 from logging import getLogger
7 from typing import Any, cast, List
11 from .protomodule import ProtoModule
12 from .zmsg import Bcast
14 log = getLogger("loctrkd/watch")
17 pmods: List[ProtoModule] = []
20 def runserver(conf: ConfigParser) -> None:
23 cast(ProtoModule, import_module("." + modnm, __package__))
24 for modnm in conf.get("common", "protocols").split(",")
26 # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?!
27 zctx = zmq.Context() # type: ignore
28 zsub = zctx.socket(zmq.SUB) # type: ignore
29 zsub.connect(conf.get("collector", "publishurl"))
30 zsub.setsockopt(zmq.SUBSCRIBE, b"")
34 zmsg = Bcast(zsub.recv())
35 print("I" if zmsg.is_incoming else "O", zmsg.proto, zmsg.imei)
37 if pmod.proto_handled(zmsg.proto):
38 msg = pmod.parse_message(zmsg.packet, zmsg.is_incoming)
40 except KeyboardInterrupt:
44 if __name__.endswith("__main__"):
45 runserver(common.init(log))