X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fopencellid.py;h=ff193fd27a5f511787c9b3b671a22ce217f06a58;hb=4685264dbad5f904124e9bb390a36c8902a544d5;hp=22aedcf6e777fa44c2b97ea4039fbc23fb2a7a45;hpb=456fcc5a8964c84385d34a6687e83ae05ab2ddc3;p=loctrkd.git diff --git a/loctrkd/opencellid.py b/loctrkd/opencellid.py index 22aedcf..ff193fd 100644 --- a/loctrkd/opencellid.py +++ b/loctrkd/opencellid.py @@ -2,6 +2,7 @@ Lookaside backend to query local opencellid database """ +from configparser import ConfigParser from sqlite3 import connect from typing import Any, Dict, List, Tuple @@ -10,7 +11,7 @@ __all__ = "init", "lookup" ldb = None -def init(conf: Dict[str, Any]) -> None: +def init(conf: ConfigParser) -> None: global ldb ldb = connect(conf["opencellid"]["dbfn"]) @@ -42,13 +43,13 @@ def lookup( (mcc,), ) data = list(lc.fetchall()) + # lc.execute("drop table mem.seen") + lc.execute("""detach database mem""") + lc.close() if not data: - return 0.0, 0.0 + raise ValueError("No location data found in opencellid") sumsig = sum([1 / sig for _, _, sig in data]) nsigs = [1 / sig / sumsig for _, _, sig in data] avlat = sum([lat * nsig for (lat, _, _), nsig in zip(data, nsigs)]) avlon = sum([lon * nsig for (_, lon, _), nsig in zip(data, nsigs)]) - # lc.execute("drop table mem.seen") - lc.execute("""detach database mem""") - lc.close() return avlat, avlon