X-Git-Url: http://www.average.org/gitweb/?p=loctrkd.git;a=blobdiff_plain;f=gps303%2Fevstore.py;h=c10ecb17e5d7a191d7bf75a76e768138cc9c2755;hp=70a3ac6618bec9bd67f53ff7fa9a30a6d92484c4;hb=96538346bd332d76d2cac5d6a0ef2b4e4a40de30;hpb=0c9ed98ee47630e854047f1e0fcf29326e137e36 diff --git a/gps303/evstore.py b/gps303/evstore.py index 70a3ac6..c10ecb1 100644 --- a/gps303/evstore.py +++ b/gps303/evstore.py @@ -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