diff options
Diffstat (limited to 'foursquare/query_poi.py')
-rw-r--r-- | foursquare/query_poi.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/foursquare/query_poi.py b/foursquare/query_poi.py new file mode 100644 index 0000000..efdd1b1 --- /dev/null +++ b/foursquare/query_poi.py | |||
@@ -0,0 +1,33 @@ | |||
1 | import requests | ||
2 | import json | ||
3 | from config import FSQ_API_KEY | ||
4 | from dbstore.dbm_store import get_loc, store_loc | ||
5 | |||
6 | POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}" | ||
7 | OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M" | ||
8 | |||
9 | def query_poi(latitude, longitude): | ||
10 | locations = list() | ||
11 | |||
12 | url = POI_API_ENDPOINT.format(latitude, longitude) | ||
13 | headers = { | ||
14 | "accept": "application/json", | ||
15 | "Authorization": FSQ_API_KEY | ||
16 | } | ||
17 | |||
18 | response = requests.get(url, headers=headers) | ||
19 | |||
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 | ||