diff options
author | clarkzjw <[email protected]> | 2023-02-20 13:47:26 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-20 13:47:26 -0800 |
commit | f7f99f41e768e6740adbf2ee708488b29fe6265a (patch) | |
tree | 125b6ec833af57b2ec1813309506dbe6b791b35f /dbstore | |
parent | 3a230798be1bc63b363cf75b8b1cae3a508cca84 (diff) | |
download | swarm2fediverse-f7f99f41e768e6740adbf2ee708488b29fe6265a.tar.gz |
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
Diffstat (limited to 'dbstore')
-rw-r--r-- | dbstore/dbm_store.py | 34 |
1 files changed, 34 insertions, 0 deletions
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 @@ | |||
1 | import dbm | ||
2 | |||
3 | db = None | ||
4 | store_file = "fsq_poi.db" | ||
5 | |||
6 | |||
7 | def get_loc(fsq_id): | ||
8 | global db | ||
9 | if db is None: | ||
10 | db = dbm.open(store_file, 'c') | ||
11 | if fsq_id in db: | ||
12 | res = db[fsq_id].decode("utf-8").split("|") | ||
13 | return { | ||
14 | "name": res[0], | ||
15 | "locality": res[1], | ||
16 | "region": res[2], | ||
17 | "latitude": res[3], | ||
18 | "longitude": res[4], | ||
19 | "osm_url": res[5], | ||
20 | } | ||
21 | else: | ||
22 | return None | ||
23 | |||
24 | |||
25 | def store_loc(loc): | ||
26 | global db | ||
27 | if db is None: | ||
28 | db = dbm.open(store_file, 'c') | ||
29 | db[loc["fsq_id"]] = "{}|{}|{}|{}|{}|{}".format(loc["name"], | ||
30 | loc["locality"], | ||
31 | loc["region"], | ||
32 | loc["latitude"], | ||
33 | loc["longitude"], | ||
34 | loc["osm_url"]) | ||