1 from datetime import datetime, timezone
2 from sqlite3 import connect
5 from .gps303proto import *
6 from .opencellid import qry_cell
8 db = connect(sys.argv[1])
11 "select tstamp, packet from events where proto in ({})".format(
16 WIFI_POSITIONING.PROTO,
17 WIFI_OFFLINE_POSITIONING.PROTO,
18 GPS_POSITIONING.PROTO,
19 GPS_OFFLINE_POSITIONING.PROTO,
27 """<?xml version="1.0"?>
30 xmlns="http://www.topografix.com/GPX/1/1">
31 <name>Location Data</name>
33 <name>Location Data</name>
38 for tstamp, packet in c:
39 msg = parse_message(packet)
40 if isinstance(msg, (WIFI_POSITIONING, WIFI_OFFLINE_POSITIONING)):
41 lat, lon = qry_cell(sys.argv[2], msg.mcc, msg.gsm_cells)
42 if lat is None or lon is None:
44 elif isinstance(msg, (GPS_POSITIONING, GPS_OFFLINE_POSITIONING)):
45 lat, lon = msg.latitude, msg.longitude
49 datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat()
51 isotime = isotime[: isotime.rfind(".")] + "Z"
52 trkpt = """ <trkpt lat="{}" lon="{}">
60 datetime.fromtimestamp(tstamp)
61 .astimezone(tz=timezone.utc)