]> www.average.org Git - loctrkd.git/commitdiff
update mkgpx to the new api
authorEugene Crosser <crosser@average.org>
Wed, 27 Apr 2022 19:58:59 +0000 (21:58 +0200)
committerEugene Crosser <crosser@average.org>
Wed, 27 Apr 2022 19:58:59 +0000 (21:58 +0200)
gps303/mkgpx.py

index 0d1fe8959b8dbf7ab4680d58b1360cf0b3ce0eae..40588a0885791b347d5f3fc2ddb0f43a1b560cb6 100644 (file)
@@ -7,9 +7,8 @@ from .opencellid import qry_cell
 
 db = connect(sys.argv[1])
 c = db.cursor()
-c.execute(
-    "select timestamp, imei, clntaddr, length, proto, payload from events"
-)
+c.execute("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("""<?xml version="1.0"?>
 <gpx version="1.1"
@@ -21,8 +20,8 @@ xmlns="http://www.topografix.com/GPX/1/1">
     <trkseg>
 """)
 
-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)
         if lat is None or lon is None:
@@ -31,7 +30,7 @@ for timestamp, imei, clntaddr, length, proto, payload in c:
         lat, lon = msg.latitude, msg.longitude
     else:
         continue
-    isotime = datetime.fromtimestamp(timestamp).astimezone(tz=timezone.utc).isoformat()
+    isotime = datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat()
     isotime = isotime[:isotime.rfind(".")] + "Z"
     trkpt = """      <trkpt lat="{}" lon="{}">
           <time>{}</time>
@@ -39,7 +38,7 @@ for timestamp, imei, clntaddr, length, proto, payload in c:
     print(trkpt)
     if False:
         print(
-            datetime.fromtimestamp(timestamp)
+            datetime.fromtimestamp(tstamp)
             .astimezone(tz=timezone.utc)
             .isoformat(),
             msg,