X-Git-Url: http://www.average.org/gitweb/?a=blobdiff_plain;f=gps303%2Fmkgpx.py;h=55cc943cc1787ddc53a8fc71c001cc95ed7edd8e;hb=1888de5a5dd4bdb85f3fb745341920a9996b278e;hp=0d1fe8959b8dbf7ab4680d58b1360cf0b3ce0eae;hpb=b613110bb16c95d9b641882c2ad6869e3ced1a0c;p=loctrkd.git diff --git a/gps303/mkgpx.py b/gps303/mkgpx.py index 0d1fe89..55cc943 100644 --- a/gps303/mkgpx.py +++ b/gps303/mkgpx.py @@ -3,15 +3,29 @@ from sqlite3 import connect import sys from .gps303proto import * -from .opencellid import qry_cell +from . import opencellid as ocid +ocid.init({"opencellid": {"dbfn": sys.argv[2]}}) db = connect(sys.argv[1]) c = db.cursor() c.execute( - "select timestamp, imei, clntaddr, length, proto, payload from events" + "select tstamp, packet from events where proto in ({})".format( + ", ".join( + [ + str(n) + for n in ( + WIFI_POSITIONING.PROTO, + WIFI_OFFLINE_POSITIONING.PROTO, + GPS_POSITIONING.PROTO, + GPS_OFFLINE_POSITIONING.PROTO, + ) + ] + ) + ) ) -print(""" +print( + """ @@ -19,31 +33,38 @@ xmlns="http://www.topografix.com/GPX/1/1"> Location Data -""") +""" +) -for timestamp, imei, clntaddr, length, proto, payload in c: - msg = make_object(length, proto, payload) +for tstamp, packet in c: + msg = parse_message(packet) if isinstance(msg, (WIFI_POSITIONING, WIFI_OFFLINE_POSITIONING)): - lat, lon = qry_cell(sys.argv[2], msg.mcc, msg.gsm_cells) + lat, lon = ocid.lookup(msg.mcc, msg.mnc, msg.gsm_cells, msg.wifi_aps) if lat is None or lon is None: continue elif isinstance(msg, (GPS_POSITIONING, GPS_OFFLINE_POSITIONING)): lat, lon = msg.latitude, msg.longitude else: continue - isotime = datetime.fromtimestamp(timestamp).astimezone(tz=timezone.utc).isoformat() - isotime = isotime[:isotime.rfind(".")] + "Z" + isotime = ( + datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat() + ) + isotime = isotime[: isotime.rfind(".")] + "Z" trkpt = """ - """.format(lat, lon, isotime) + """.format( + lat, lon, isotime + ) print(trkpt) if False: print( - datetime.fromtimestamp(timestamp) + datetime.fromtimestamp(tstamp) .astimezone(tz=timezone.utc) .isoformat(), msg, ) -print(""" +print( + """ -""") +""" +)