]> www.average.org Git - loctrkd.git/blobdiff - gps303/evstore.py
WIP on baclog fetcher
[loctrkd.git] / gps303 / evstore.py
index 70a3ac6618bec9bd67f53ff7fa9a30a6d92484c4..c10ecb17e5d7a191d7bf75a76e768138cc9c2755 100644 (file)
@@ -2,7 +2,7 @@
 
 from sqlite3 import connect
 
-__all__ = "initdb", "stow"
+__all__ = "fetch", "initdb", "stow"
 
 DB = None
 
@@ -43,3 +43,15 @@ def stow(**kwargs):
         parms,
     )
     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
+                    where proto in ({protosel}) and imei = ?
+                    order by tstamp desc limit ?""",
+                protos + (imei, backlog))
+    result = [row[0] for row in cur]
+    cur.close()
+    return result