diff options
author | clarkzjw <[email protected]> | 2023-02-21 17:39:59 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-21 17:39:59 -0800 |
commit | 5b09e9d190b642a4e5571c0e4504c155f56a6f5a (patch) | |
tree | e4a1ea917b1f5e56d34394ac4d62bb0e71571bf3 /foursquare | |
parent | 431e8abcc4bf858e4ca945384a2f60702f1b5a4c (diff) | |
download | swarm2fediverse-5b09e9d190b642a4e5571c0e4504c155f56a6f5a.tar.gz |
bot: enable location search
Diffstat (limited to 'foursquare')
-rw-r--r-- | foursquare/poi.py | 14 |
1 files changed, 8 insertions, 6 deletions
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 | |||
5 | from config import FSQ_API_KEY | 5 | from config import FSQ_API_KEY |
6 | from dbstore.dbm_store import store_loc | 6 | from dbstore.dbm_store import store_loc |
7 | 7 | ||
8 | POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}" | 8 | POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}&limit=10" |
9 | POI_SEARCH_API_ENDPOINT = "https://api.foursquare.com/v3/places/search?query={}&ll={}%2C{}&radius=2000&limit=10" | ||
9 | POI_PHOTO_ENDPOINT = "https://api.foursquare.com/v3/places/{}/photos?sort=POPULAR&limit=10" | 10 | POI_PHOTO_ENDPOINT = "https://api.foursquare.com/v3/places/{}/photos?sort=POPULAR&limit=10" |
10 | OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M" | 11 | OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M" |
11 | headers = { | 12 | headers = { |
@@ -14,24 +15,25 @@ headers = { | |||
14 | } | 15 | } |
15 | 16 | ||
16 | 17 | ||
17 | def query_poi(latitude, longitude): | 18 | def query_poi(search, latitude, longitude): |
18 | locations = list() | 19 | locations = list() |
19 | 20 | ||
20 | url = POI_API_ENDPOINT.format(latitude, longitude) | 21 | url = POI_SEARCH_API_ENDPOINT.format(search, latitude, longitude) |
21 | 22 | print(url) | |
22 | response = requests.get(url, headers=headers) | 23 | response = requests.get(url, headers=headers) |
23 | 24 | ||
24 | for poi in json.loads(response.text)["results"]: | 25 | for poi in json.loads(response.text)["results"]: |
25 | loc = { | 26 | loc = { |
26 | "fsq_id": poi["fsq_id"], | 27 | "fsq_id": poi["fsq_id"], |
27 | "name": poi["name"], | 28 | "name": poi["name"], |
28 | "locality": poi["location"]["locality"], | 29 | "locality": poi["location"]["locality"] if "locality" in poi["location"] else "", |
29 | "region": poi["location"]["region"], | 30 | "region": poi["location"]["region"] if "region" in poi["location"] else "", |
30 | "latitude": poi["geocodes"]["main"]["latitude"], | 31 | "latitude": poi["geocodes"]["main"]["latitude"], |
31 | "longitude": poi["geocodes"]["main"]["longitude"], | 32 | "longitude": poi["geocodes"]["main"]["longitude"], |
32 | "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"]) | 33 | "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"]) |
33 | } | 34 | } |
34 | locations.append(loc) | 35 | locations.append(loc) |
36 | print(loc) | ||
35 | store_loc(loc) | 37 | store_loc(loc) |
36 | 38 | ||
37 | return locations | 39 | return locations |