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))
30 resp = Resp(imei=imei, packet=cls.response(**kwargs))
31 log.debug("Response: %s", resp)
32 zpush.send(resp.packed)
35 if __name__.endswith("__main__"):
36 opts, args = getopt(argv[1:], "c:d")
37 main(common.init(log, opts=opts), opts, args)