diff options
author | clarkzjw <[email protected]> | 2023-02-20 13:49:51 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-20 13:49:51 -0800 |
commit | f927324709d639adfcd5487c7740e3d60f2246b8 (patch) | |
tree | 125b6ec833af57b2ec1813309506dbe6b791b35f /foursquare | |
parent | a099e6cf153ae7155957bb16bc56233d2420288c (diff) | |
parent | f7f99f41e768e6740adbf2ee708488b29fe6265a (diff) | |
download | swarm2fediverse-f927324709d639adfcd5487c7740e3d60f2246b8.tar.gz |
basic features
Diffstat (limited to 'foursquare')
-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 | ||