From f7f99f41e768e6740adbf2ee708488b29fe6265a Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Mon, 20 Feb 2023 13:47:26 -0800 Subject: implemented basic functions: - send a location from Telegram to bot - query a list (7) of POIs from Foursquare - send user inline keyboard button to choose a location - post toot status update to Mastodon with a link to OSM - store previously seen locations in local db --- dbstore/dbm_store.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 dbstore/dbm_store.py (limited to 'dbstore') diff --git a/dbstore/dbm_store.py b/dbstore/dbm_store.py new file mode 100644 index 0000000..fedb505 --- /dev/null +++ b/dbstore/dbm_store.py @@ -0,0 +1,34 @@ +import dbm + +db = None +store_file = "fsq_poi.db" + + +def get_loc(fsq_id): + global db + if db is None: + db = dbm.open(store_file, 'c') + if fsq_id in db: + res = db[fsq_id].decode("utf-8").split("|") + return { + "name": res[0], + "locality": res[1], + "region": res[2], + "latitude": res[3], + "longitude": res[4], + "osm_url": res[5], + } + else: + return None + + +def store_loc(loc): + global db + if db is None: + db = dbm.open(store_file, 'c') + db[loc["fsq_id"]] = "{}|{}|{}|{}|{}|{}".format(loc["name"], + loc["locality"], + loc["region"], + loc["latitude"], + loc["longitude"], + loc["osm_url"]) -- cgit v1.2.3