1 from datetime import datetime, timezone
2 from sqlite3 import connect
5 from .gps303proto import *
6 from . import opencellid as ocid
8 ocid.init({"opencellid": {"dbfn": sys.argv[2]}})
9 db = connect(sys.argv[1])
12 "select tstamp, packet from events where proto in ({})".format(
17 WIFI_POSITIONING.PROTO,
18 WIFI_OFFLINE_POSITIONING.PROTO,
19 GPS_POSITIONING.PROTO,
20 GPS_OFFLINE_POSITIONING.PROTO,
28 """<?xml version="1.0"?>
31 xmlns="http://www.topografix.com/GPX/1/1">
32 <name>Location Data</name>
34 <name>Location Data</name>
39 for tstamp, packet in c:
40 msg = parse_message(packet)
41 if isinstance(msg, (WIFI_POSITIONING, WIFI_OFFLINE_POSITIONING)):
42 lat, lon = ocid.lookup(msg.mcc, msg.mnc, msg.gsm_cells, msg.wifi_aps)
43 if lat is None or lon is None:
45 elif isinstance(msg, (GPS_POSITIONING, GPS_OFFLINE_POSITIONING)):
46 lat, lon = msg.latitude, msg.longitude
50 datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat()
52 isotime = isotime[: isotime.rfind(".")] + "Z"
53 trkpt = """ <trkpt lat="{}" lon="{}">
61 datetime.fromtimestamp(tstamp)
62 .astimezone(tz=timezone.utc)