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
10 from .gps303proto import *
11 from .zmsg import Bcast, Resp
13 log = getLogger("gps303")
16 def main(conf, opts, args):
18 zpush = zctx.socket(zmq.PUSH)
19 zpush.connect(conf.get("collector", "listenurl"))
22 raise ValueError("Too few args, need IMEI and command min: " + str(args))
26 cls = class_by_prefix(cmd)
27 if isinstance(cls, list):
28 raise ValueError("Prefix does not select a single class: " + str(cls))
29 kwargs = dict([arg.split("=") for arg in args])
33 resp = Resp(imei=imei, packet=cls.Out(**kwargs).packed)
34 log.debug("Response: %s", resp)
35 zpush.send(resp.packed)
38 if __name__.endswith("__main__"):
39 opts, args = getopt(argv[1:], "c:d")
40 main(common.init(log, opts=opts), opts, args)