]> www.average.org Git - loctrkd.git/blobdiff - gps303/__main__.py
Rename gps303proto to zx303proto
[loctrkd.git] / gps303 / __main__.py
index 38d21fe6eea049c7e17030a4028976ba827b1898..fcd07a6380ff43ec3c8d1060ebcfba57da443a99 100644 (file)
@@ -1,25 +1,33 @@
 """ Command line tool for sending requests to the terminal """
 
+from configparser import ConfigParser
 from datetime import datetime, timezone
 from getopt import getopt
 from logging import getLogger
 from sys import argv
+from time import time
+from typing import List, Tuple
 import zmq
 
 from . import common
-from .gps303proto import *
+from .zx303proto import *
 from .zmsg import Bcast, Resp
 
 log = getLogger("gps303")
 
 
-def main(conf, opts, args):
-    zctx = zmq.Context()
-    zpush = zctx.socket(zmq.PUSH)
+def main(
+    conf: ConfigParser, opts: List[Tuple[str, str]], args: List[str]
+) -> None:
+    # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?!
+    zctx = zmq.Context()  # type: ignore
+    zpush = zctx.socket(zmq.PUSH)  # type: ignore
     zpush.connect(conf.get("collector", "listenurl"))
 
     if len(args) < 2:
-        raise ValueError("Too few args, need IMEI and command min: " + str(args))
+        raise ValueError(
+            "Too few args, need IMEI and command min: " + str(args)
+        )
     imei = args[0]
     cmd = args[1]
     args = args[2:]
@@ -30,7 +38,7 @@ def main(conf, opts, args):
     for arg in args:
         k, v = arg.split("=")
         kwargs[k] = v
-    resp = Resp(imei=imei, packet=cls.Out(**kwargs).packed)
+    resp = Resp(imei=imei, when=time(), packet=cls.Out(**kwargs).packed)
     log.debug("Response: %s", resp)
     zpush.send(resp.packed)