X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fmkgpx.py;h=6d1ee27ab07024a471ca45b98069709c354b6ab5;hb=a8fcc61066d792404e6343e065270484ae18c7a3;hp=115dd806cf9da08a6292bdbc7685164e3eb85ed9;hpb=dbdf9d63af31770ad57302e16b17a2fdc526773f;p=loctrkd.git diff --git a/loctrkd/mkgpx.py b/loctrkd/mkgpx.py index 115dd80..6d1ee27 100644 --- a/loctrkd/mkgpx.py +++ b/loctrkd/mkgpx.py @@ -1,60 +1,79 @@ """ Example that produces gpx from events in evstore """ # run as: -# python -m loctrkd.mkgpx +# python -m loctrkd.mkgpx # Generated gpx is emitted to stdout +from configparser import ConfigParser from datetime import datetime, timezone +from getopt import getopt +from importlib import import_module +from logging import getLogger from sqlite3 import connect -import sys - -from .zx303proto import * - -db = connect(sys.argv[1]) -c = db.cursor() -c.execute( - """select tstamp, is_incoming, packet from events - where imei = ? - and ((is_incoming = false and proto = ?) - or (is_incoming = true and proto = ?)) - order by tstamp""", - (sys.argv[2], proto_name(WIFI_POSITIONING), proto_name(GPS_POSITIONING)), -) - -print( - """ - - Location Data - - Location Data - -""" -) - -for tstamp, is_incoming, packet in c: - msg = parse_message(packet, is_incoming=is_incoming) - lat, lon = msg.latitude, msg.longitude - isotime = ( - datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat() +from sys import argv +from typing import Any, cast, List, Tuple + +from . import common +from .protomodule import ProtoModule + +log = getLogger("loctrkd/mkgpx") + + +def main( + conf: ConfigParser, opts: List[Tuple[str, str]], args: List[str] +) -> None: + db = connect(conf.get("storage", "dbfn")) + c = db.cursor() + c.execute( + """select tstamp, is_incoming, proto, packet from events + where imei = ? and is_incoming = true + and proto in (?, ?) + order by tstamp""", + (args[0], "BS:UD", "BS:UD2"), ) - isotime = isotime[: isotime.rfind(".")] + "Z" - trkpt = """ - - """.format( - lat, lon, isotime + print( + """ + + Location Data + + Location Data + + """ ) - print(trkpt) - if False: - print( + + for tstamp, is_incoming, proto, packet in c: + pmod = common.pmod_for_proto(proto) + if pmod is not None: + msg = pmod.parse_message(packet, is_incoming=is_incoming) + lat, lon = msg.latitude, msg.longitude + isotime = ( datetime.fromtimestamp(tstamp) .astimezone(tz=timezone.utc) - .isoformat(), - msg, + .isoformat() ) -print( - """ - -""" -) + isotime = isotime[: isotime.rfind(".")] + "Z" + trkpt = """ + + """.format( + lat, lon, isotime + ) + print(trkpt) + if False: + print( + datetime.fromtimestamp(tstamp) + .astimezone(tz=timezone.utc) + .isoformat(), + msg, + ) + print( + """ + + """ + ) + + +if __name__.endswith("__main__"): + opts, args = getopt(argv[1:], "o:c:d") + main(common.init(log, opts=opts), opts, args)