aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-20 14:45:17 -0800
committerclarkzjw <[email protected]>2023-02-20 14:45:17 -0800
commitfda33866814e95830466787ae9cea2e006386e85 (patch)
tree4ba189c8e44fa32bd6c89960a9e28d171ffb89f3 /foursquare/poi.py
parent88ad58c3d3412162ffdeb96f49b789e7976cad07 (diff)
downloadswarm2fediverse-fda33866814e95830466787ae9cea2e006386e85.tar.gz
attach top popular photo to mastodon media post
Diffstat (limited to 'foursquare/poi.py')
-rw-r--r--foursquare/poi.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/foursquare/poi.py b/foursquare/poi.py
new file mode 100644
index 0000000..722dbb7
--- /dev/null
+++ b/foursquare/poi.py
@@ -0,0 +1,53 @@
1import json
2
3import requests
4
5from config import FSQ_API_KEY
6from dbstore.dbm_store import store_loc
7
8POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}"
9POI_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"
11headers = {
12 "accept": "application/json",
13 "Authorization": FSQ_API_KEY
14}
15
16
17def query_poi(latitude, longitude):
18 locations = list()
19
20 url = POI_API_ENDPOINT.format(latitude, longitude)
21
22 response = requests.get(url, headers=headers)
23
24 for poi in json.loads(response.text)["results"]:
25 loc = {
26 "fsq_id": poi["fsq_id"],
27 "name": poi["name"],
28 "locality": poi["location"]["locality"],
29 "region": poi["location"]["region"],
30 "latitude": poi["geocodes"]["main"]["latitude"],
31 "longitude": poi["geocodes"]["main"]["longitude"],
32 "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"])
33 }
34 locations.append(loc)
35 store_loc(loc)
36
37 return locations
38
39
40def get_poi_top_photo(fsq_id):
41 url = POI_PHOTO_ENDPOINT.format(fsq_id)
42 response = requests.get(url, headers=headers)
43
44 poi_photo_urls = []
45 for poi in json.loads(response.text):
46 prefix = poi["prefix"]
47 suffix = poi["suffix"]
48 poi_photo_urls.append(prefix + "original" + suffix)
49
50 if len(poi_photo_urls) == 0:
51 return None
52
53 return poi_photo_urls[0]
Powered by cgit v1.2.3 (git 2.41.0)