From f7f99f41e768e6740adbf2ee708488b29fe6265a Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Mon, 20 Feb 2023 13:47:26 -0800 Subject: 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 --- foursquare/query_poi.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'foursquare') 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 @@ import requests import json from config import FSQ_API_KEY +from dbstore.dbm_store import get_loc, store_loc POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}" - +OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M" def query_poi(latitude, longitude): - url = POI_API_ENDPOINT.format(latitude, longitude) + locations = list() + url = POI_API_ENDPOINT.format(latitude, longitude) headers = { "accept": "application/json", "Authorization": FSQ_API_KEY } response = requests.get(url, headers=headers) - print(response.text) - return json.loads(response.text)["results"][:2] + + 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"], + "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) + store_loc(loc) + + return locations -- cgit v1.2.3