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])
10 c.execute("select tstamp, packet from events where proto in ({})"
11 .format(", ".join([str(n) for n in (WIFI_POSITIONING.PROTO, WIFI_OFFLINE_POSITIONING.PROTO, GPS_POSITIONING.PROTO, GPS_OFFLINE_POSITIONING.PROTO)])))
13 print("""<?xml version="1.0"?>
16 xmlns="http://www.topografix.com/GPX/1/1">
17 <name>Location Data</name>
19 <name>Location Data</name>
23 for tstamp, packet in c:
24 msg = parse_message(packet)
25 if isinstance(msg, (WIFI_POSITIONING, WIFI_OFFLINE_POSITIONING)):
26 lat, lon = qry_cell(sys.argv[2], msg.mcc, msg.gsm_cells)
27 if lat is None or lon is None:
29 elif isinstance(msg, (GPS_POSITIONING, GPS_OFFLINE_POSITIONING)):
30 lat, lon = msg.latitude, msg.longitude
33 isotime = datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat()
34 isotime = isotime[:isotime.rfind(".")] + "Z"
35 trkpt = """ <trkpt lat="{}" lon="{}">
37 </trkpt>""".format(lat, lon, isotime)
41 datetime.fromtimestamp(tstamp)
42 .astimezone(tz=timezone.utc)