From 5b09e9d190b642a4e5571c0e4504c155f56a6f5a Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 21 Feb 2023 17:39:59 -0800 Subject: bot: enable location search --- foursquare/poi.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'foursquare') diff --git a/foursquare/poi.py b/foursquare/poi.py index 722dbb7..5e67d1c 100644 --- a/foursquare/poi.py +++ b/foursquare/poi.py @@ -5,7 +5,8 @@ import requests from config import FSQ_API_KEY from dbstore.dbm_store import store_loc -POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}" +POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}&limit=10" +POI_SEARCH_API_ENDPOINT = "https://api.foursquare.com/v3/places/search?query={}&ll={}%2C{}&radius=2000&limit=10" POI_PHOTO_ENDPOINT = "https://api.foursquare.com/v3/places/{}/photos?sort=POPULAR&limit=10" OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M" headers = { @@ -14,24 +15,25 @@ headers = { } -def query_poi(latitude, longitude): +def query_poi(search, latitude, longitude): locations = list() - url = POI_API_ENDPOINT.format(latitude, longitude) - + url = POI_SEARCH_API_ENDPOINT.format(search, latitude, longitude) + print(url) response = requests.get(url, headers=headers) for poi in json.loads(response.text)["results"]: loc = { "fsq_id": poi["fsq_id"], "name": poi["name"], - "locality": poi["location"]["locality"], - "region": poi["location"]["region"], + "locality": poi["location"]["locality"] if "locality" in poi["location"] else "", + "region": poi["location"]["region"] if "region" in poi["location"] else "", "latitude": poi["geocodes"]["main"]["latitude"], "longitude": poi["geocodes"]["main"]["longitude"], "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"]) } locations.append(loc) + print(loc) store_loc(loc) return locations -- cgit v1.2.3