X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=gps303%2F__main__.py;h=2ad2ecfea0aaacab36aeae9cf526ad8067f58734;hb=refs%2Ftags%2F1.02;hp=aa2342793cee364ca9b4404f434bfaf55395dbe8;hpb=9b5436a2e568931f38e5721cdcf2e42bab151619;p=loctrkd.git diff --git a/gps303/__main__.py b/gps303/__main__.py index aa23427..2ad2ecf 100644 --- a/gps303/__main__.py +++ b/gps303/__main__.py @@ -1,9 +1,12 @@ """ 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 @@ -13,21 +16,29 @@ 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:] cls = class_by_prefix(cmd) if isinstance(cls, list): raise ValueError("Prefix does not select a single class: " + str(cls)) - kwargs = {} - resp = Resp(imei=imei, packet=cls.Out(**kwargs).packed) + kwargs = dict([arg.split("=") for arg in args]) + for arg in args: + k, v = arg.split("=") + kwargs[k] = v + resp = Resp(imei=imei, when=time(), packet=cls.Out(**kwargs).packed) log.debug("Response: %s", resp) zpush.send(resp.packed)