from datetime import datetime
from json import dumps, loads
from sqlite3 import connect, OperationalError, Row
-from typing import Any, Dict, List, Tuple
+from typing import Any, Dict, List, Optional, Tuple
__all__ = "fetch", "initdb", "stow", "stowloc"
latitude real,
longitude real,
remainder text
+)""",
+ """create table if not exists pmodmap (
+ imei text not null unique,
+ pmod text not null
)""",
)
DB.commit()
+def stowpmod(imei: str, pmod: str) -> None:
+ assert DB is not None
+ DB.execute(
+ """insert or replace into pmodmap
+ (imei, pmod) values (:imei, :pmod)
+ """,
+ {"imei": imei, "pmod": pmod},
+ )
+ DB.commit()
+
+
def fetch(imei: str, backlog: int) -> List[Dict[str, Any]]:
assert DB is not None
cur = DB.cursor()
result.append(dic)
cur.close()
return list(reversed(result))
+
+
+def fetchpmod(imei: str) -> Optional[Any]:
+ assert DB is not None
+ ret = None
+ cur = DB.cursor()
+ cur.execute("select pmod from pmodmap where imei = ?", (imei,))
+ result = cur.fetchone()
+ if result:
+ ret = result[0]
+ cur.close()
+ return ret