aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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)