aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-22 23:57:11 -0800
committerclarkzjw <[email protected]>2023-02-23 12:07:32 -0800
commit5402e3a2e9df24a883e2e20dfae6c92f11b8d499 (patch)
tree0337ca914685d2f52fbe34bf3fb7be89d7aa9721
parent736ba02520802499c9970afd9d1ee6a537fb2230 (diff)
downloadswarm2fediverse-5402e3a2e9df24a883e2e20dfae6c92f11b8d499.tar.gz
bot: change create_poi to create_or_update_poi
-rw-r--r--callback.py1
-rw-r--r--dbstore/peewee_store.py7
-rw-r--r--foursquare/poi.py4
3 files changed, 6 insertions, 6 deletions
diff --git a/callback.py b/callback.py
index aca8a90..23b814b 100644
--- a/callback.py
+++ b/callback.py
@@ -184,6 +184,7 @@ async def _process_location_selection(context: ContextTypes.DEFAULT_TYPE) -> int
184 poi_name = context.user_data.get("poi_name") 184 poi_name = context.user_data.get("poi_name")
185 if context.user_data.get("fsq_id") is not None: 185 if context.user_data.get("fsq_id") is not None:
186 poi = get_poi_by_fsq_id(context.user_data.get("fsq_id")) 186 poi = get_poi_by_fsq_id(context.user_data.get("fsq_id"))
187 poi_name = poi["name"]
187 content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) 188 content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"])
188 else: 189 else:
189 content = generate_toot_text(poi_name, "", "", context.user_data.get("latitude"), context.user_data.get("longitude")) 190 content = generate_toot_text(poi_name, "", "", context.user_data.get("latitude"), context.user_data.get("longitude"))
diff --git a/dbstore/peewee_store.py b/dbstore/peewee_store.py
index 00897d7..89e4b4b 100644
--- a/dbstore/peewee_store.py
+++ b/dbstore/peewee_store.py
@@ -52,14 +52,13 @@ def get_poi_by_fsq_id(fsq_id) -> dict:
52 return {} 52 return {}
53 53
54 54
55def create_poi(poi: dict): 55def create_or_update_poi(poi: dict) -> int:
56 with db.connection_context(): 56 with db.connection_context():
57 poi = Location.create( 57 return Location.insert(
58 fsq_id=poi["fsq_id"], 58 fsq_id=poi["fsq_id"],
59 name=poi["name"], 59 name=poi["name"],
60 locality=poi["locality"], 60 locality=poi["locality"],
61 region=poi["region"], 61 region=poi["region"],
62 latitude=poi["latitude"], 62 latitude=poi["latitude"],
63 longitude=poi["longitude"], 63 longitude=poi["longitude"],
64 ) 64 ).on_conflict_replace().execute()
65 poi.save()
diff --git a/foursquare/poi.py b/foursquare/poi.py
index 4ff11fb..ea3509f 100644
--- a/foursquare/poi.py
+++ b/foursquare/poi.py
@@ -3,7 +3,7 @@ import json
3import requests 3import requests
4 4
5from config import FSQ_API_KEY 5from config import FSQ_API_KEY
6from dbstore.peewee_store import create_poi 6from dbstore.peewee_store import create_or_update_poi
7 7
8POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}&limit=10" 8POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}&limit=10"
9POI_SEARCH_API_ENDPOINT = "https://api.foursquare.com/v3/places/search?query={}&ll={}%2C{}&radius=2000&limit=10" 9POI_SEARCH_API_ENDPOINT = "https://api.foursquare.com/v3/places/search?query={}&ll={}%2C{}&radius=2000&limit=10"
@@ -32,7 +32,7 @@ def query_poi(search, latitude, longitude):
32 "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"]) 32 "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"])
33 } 33 }
34 locations.append(loc) 34 locations.append(loc)
35 create_poi(loc) 35 create_or_update_poi(loc)
36 36
37 return locations 37 return locations
38 38
Powered by cgit v1.2.3 (git 2.41.0)