aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-20 13:49:51 -0800
committerclarkzjw <[email protected]>2023-02-20 13:49:51 -0800
commitf927324709d639adfcd5487c7740e3d60f2246b8 (patch)
tree125b6ec833af57b2ec1813309506dbe6b791b35f /foursquare
parenta099e6cf153ae7155957bb16bc56233d2420288c (diff)
parentf7f99f41e768e6740adbf2ee708488b29fe6265a (diff)
downloadswarm2fediverse-f927324709d639adfcd5487c7740e3d60f2246b8.tar.gz
basic features
Diffstat (limited to 'foursquare')
-rw-r--r--foursquare/query_poi.py33
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 @@
1import requests
2import json
3from config import FSQ_API_KEY
4from dbstore.dbm_store import get_loc, store_loc
5
6POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}"
7OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M"
8
9def 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
Powered by cgit v1.2.3 (git 2.41.0)