aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-20 13:47:26 -0800
committerclarkzjw <[email protected]>2023-02-20 13:47:26 -0800
commitf7f99f41e768e6740adbf2ee708488b29fe6265a (patch)
tree125b6ec833af57b2ec1813309506dbe6b791b35f /foursquare/query_poi.py
parent3a230798be1bc63b363cf75b8b1cae3a508cca84 (diff)
downloadswarm2fediverse-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 'foursquare/query_poi.py')
-rw-r--r--foursquare/query_poi.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/foursquare/query_poi.py b/foursquare/query_poi.py
index 64ded55..efdd1b1 100644
--- a/foursquare/query_poi.py
+++ b/foursquare/query_poi.py
@@ -1,18 +1,33 @@
1import requests 1import requests
2import json 2import json
3from config import FSQ_API_KEY 3from config import FSQ_API_KEY
4from dbstore.dbm_store import get_loc, store_loc
4 5
5POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}" 6POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}"
6 7OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M"
7 8
8def query_poi(latitude, longitude): 9def query_poi(latitude, longitude):
9 url = POI_API_ENDPOINT.format(latitude, longitude) 10 locations = list()
10 11
12 url = POI_API_ENDPOINT.format(latitude, longitude)
11 headers = { 13 headers = {
12 "accept": "application/json", 14 "accept": "application/json",
13 "Authorization": FSQ_API_KEY 15 "Authorization": FSQ_API_KEY
14 } 16 }
15 17
16 response = requests.get(url, headers=headers) 18 response = requests.get(url, headers=headers)
17 print(response.text) 19
18 return json.loads(response.text)["results"][:2] 20 for poi in json.loads(response.text)["results"]:
21 loc = {
22 "fsq_id": poi["fsq_id"],
23 "name": poi["name"],
24 "locality": poi["location"]["locality"],
25 "region": poi["location"]["region"],
26 "latitude": poi["geocodes"]["main"]["latitude"],
27 "longitude": poi["geocodes"]["main"]["longitude"],
28 "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"])
29 }
30 locations.append(loc)
31 store_loc(loc)
32
33 return locations
Powered by cgit v1.2.3 (git 2.41.0)