]> www.average.org Git - loctrkd.git/blob - gps303/qry.py
Remove deprecated functions
[loctrkd.git] / gps303 / qry.py
1 from datetime import datetime, timezone
2 from sqlite3 import connect
3 import sys
4
5 from .gps303proto import parse_message, proto_by_name
6
7 db = connect(sys.argv[1])
8 c = db.cursor()
9 if len(sys.argv) > 2:
10     proto = proto_by_name(sys.argv[2])
11     if proto < 0:
12         raise ValueError("No protocol with name " + sys.argv[2])
13     selector = " where proto = :proto"
14 else:
15     proto = -1
16     selector = ""
17
18 c.execute(
19     "select tstamp, imei, peeraddr, proto, packet from events" +
20     selector, {"proto": proto}
21 )
22
23 for tstamp, imei, peeraddr, proto, packet in c:
24     msg = parse_message(packet)
25     print(
26         datetime.fromtimestamp(tstamp)
27         .astimezone(tz=timezone.utc)
28         .isoformat(),
29         imei,
30         peeraddr,
31         msg,
32     )