1 """ Command line tool for sending requests to the terminal """
3 from datetime import datetime, timezone
4 from getopt import getopt
5 from logging import getLogger
11 from .gps303proto import *
12 from .zmsg import Bcast, Resp
14 log = getLogger("gps303")
17 def main(conf, opts, args):
19 zpush = zctx.socket(zmq.PUSH)
20 zpush.connect(conf.get("collector", "listenurl"))
24 "Too few args, need IMEI and command min: " + str(args)
29 cls = class_by_prefix(cmd)
30 if isinstance(cls, list):
31 raise ValueError("Prefix does not select a single class: " + str(cls))
32 kwargs = dict([arg.split("=") for arg in args])
36 resp = Resp(imei=imei, when=time(), packet=cls.Out(**kwargs).packed)
37 log.debug("Response: %s", resp)
38 zpush.send(resp.packed)
41 if __name__.endswith("__main__"):
42 opts, args = getopt(argv[1:], "c:d")
43 main(common.init(log, opts=opts), opts, args)