aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'foursquare')
-rw-r--r--foursquare/poi.py14
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
5from config import FSQ_API_KEY 5from config import FSQ_API_KEY
6from dbstore.dbm_store import store_loc 6from dbstore.dbm_store import store_loc
7 7
8POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}" 8POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}&limit=10"
9POI_SEARCH_API_ENDPOINT = "https://api.foursquare.com/v3/places/search?query={}&ll={}%2C{}&radius=2000&limit=10"
9POI_PHOTO_ENDPOINT = "https://api.foursquare.com/v3/places/{}/photos?sort=POPULAR&limit=10" 10POI_PHOTO_ENDPOINT = "https://api.foursquare.com/v3/places/{}/photos?sort=POPULAR&limit=10"
10OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M" 11OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M"
11headers = { 12headers = {
@@ -14,24 +15,25 @@ headers = {
14} 15}
15 16
16 17
17def query_poi(latitude, longitude): 18def 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
Powered by cgit v1.2.3 (git 2.41.0)