From 8bf5efdf4f5d069b108e6fd8140f5ebd930b538e Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Mon, 9 May 2022 17:44:45 +0200 Subject: [PATCH] misc black reformatting --- gps303/evstore.py | 13 +++++++++---- gps303/mkgpx.py | 39 ++++++++++++++++++++++++++++++--------- gps303/qry.py | 21 +++++++++++++-------- 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/gps303/evstore.py b/gps303/evstore.py index 7617362..bb47f3f 100644 --- a/gps303/evstore.py +++ b/gps303/evstore.py @@ -20,8 +20,10 @@ def initdb(dbname): global DB DB = connect(dbname) try: - DB.execute("""alter table events add column - is_incoming int not null default TRUE""") + DB.execute( + """alter table events add column + is_incoming int not null default TRUE""" + ) except OperationalError: DB.execute(SCHEMA) @@ -50,14 +52,17 @@ def stow(**kwargs): ) DB.commit() + def fetch(imei, protos, backlog): assert DB is not None protosel = ", ".join(["?" for _ in range(len(protos))]) cur = DB.cursor() - cur.execute(f"""select packet from events + cur.execute( + f"""select packet from events where proto in ({protosel}) and imei = ? order by tstamp desc limit ?""", - protos + (imei, backlog)) + protos + (imei, backlog), + ) result = [row[0] for row in cur] cur.close() return result diff --git a/gps303/mkgpx.py b/gps303/mkgpx.py index 40588a0..f694b7e 100644 --- a/gps303/mkgpx.py +++ b/gps303/mkgpx.py @@ -7,10 +7,24 @@ from .opencellid import qry_cell db = connect(sys.argv[1]) c = db.cursor() -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)]))) +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(""" +print( + """ @@ -18,7 +32,8 @@ xmlns="http://www.topografix.com/GPX/1/1"> Location Data -""") +""" +) for tstamp, packet in c: msg = parse_message(packet) @@ -30,11 +45,15 @@ for tstamp, packet in c: lat, lon = msg.latitude, msg.longitude else: continue - isotime = datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat() - isotime = isotime[:isotime.rfind(".")] + "Z" + isotime = ( + datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat() + ) + isotime = isotime[: isotime.rfind(".")] + "Z" trkpt = """ - """.format(lat, lon, isotime) + """.format( + lat, lon, isotime + ) print(trkpt) if False: print( @@ -43,6 +62,8 @@ for tstamp, packet in c: .isoformat(), msg, ) -print(""" +print( + """ -""") +""" +) diff --git a/gps303/qry.py b/gps303/qry.py index 4aeb33c..25f55aa 100644 --- a/gps303/qry.py +++ b/gps303/qry.py @@ -16,19 +16,24 @@ else: selector = "" c.execute( - "select tstamp, imei, peeraddr, proto, packet from events" + - selector, {"proto": proto} + "select tstamp, imei, peeraddr, proto, packet from events" + selector, + {"proto": proto}, ) for tstamp, imei, peeraddr, proto, packet in c: - if len(packet) > packet[0] + 1: - print("proto", packet[1] , "datalen", len(packet), - "msg.length", packet[0], file=sys.stderr) + if len(packet) > packet[0] + 1: + print( + "proto", + packet[1], + "datalen", + len(packet), + "msg.length", + packet[0], + file=sys.stderr, + ) msg = parse_message(packet) print( - datetime.fromtimestamp(tstamp) - .astimezone(tz=timezone.utc) - .isoformat(), + datetime.fromtimestamp(tstamp).astimezone(tz=timezone.utc).isoformat(), imei, peeraddr, msg, -- 2.39.2