X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fwatch.py;fp=loctrkd%2Fwatch.py;h=a8a53b0dd62f04938bef519e200796986a45a3a4;hb=dbdf9d63af31770ad57302e16b17a2fdc526773f;hp=0000000000000000000000000000000000000000;hpb=bf48ccad4b4b91e7d7e09d1087f5953bc2db97d7;p=loctrkd.git diff --git a/loctrkd/watch.py b/loctrkd/watch.py new file mode 100644 index 0000000..a8a53b0 --- /dev/null +++ b/loctrkd/watch.py @@ -0,0 +1,32 @@ +""" Watch for locevt and print them """ + +from configparser import ConfigParser +from datetime import datetime, timezone +from logging import getLogger +import zmq + +from . import common +from .zx303proto import parse_message +from .zmsg import Bcast + +log = getLogger("loctrkd/watch") + + +def runserver(conf: ConfigParser) -> None: + # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?! + zctx = zmq.Context() # type: ignore + zsub = zctx.socket(zmq.SUB) # type: ignore + zsub.connect(conf.get("collector", "publishurl")) + zsub.setsockopt(zmq.SUBSCRIBE, b"") + + try: + while True: + zmsg = Bcast(zsub.recv()) + msg = parse_message(zmsg.packet, zmsg.is_incoming) + print("I" if zmsg.is_incoming else "O", zmsg.imei, msg) + except KeyboardInterrupt: + pass + + +if __name__.endswith("__main__"): + runserver(common.init(log))