aboutsummaryrefslogblamecommitdiff
blob: e2d562596ebd503980b366ea667b413ae56d0f95 (plain) (tree)
1
2
3
4
5
6
7
8
9
           


               
                              
                                       

                                                                           
                                                                                
 
 
                                   
                      
 
                                                      





                                                 














                                                                                                                     
import json

import requests

from config import FSQ_API_KEY
from dbstore.dbm_store import store_loc

POI_API_ENDPOINT = "https://api.foursquare.com/v3/places/nearby?ll={}%2C{}"
OSM_ENDPOINT = "https://www.openstreetmap.org/?mlat={}&mlon={}&zoom=15&layers=M"


def query_poi(latitude, longitude):
    locations = list()

    url = POI_API_ENDPOINT.format(latitude, longitude)
    headers = {
        "accept": "application/json",
        "Authorization": FSQ_API_KEY
    }

    response = requests.get(url, headers=headers)

    for poi in json.loads(response.text)["results"]:
        loc = {
            "fsq_id": poi["fsq_id"],
            "name": poi["name"],
            "locality": poi["location"]["locality"],
            "region": poi["location"]["region"],
            "latitude": poi["geocodes"]["main"]["latitude"],
            "longitude": poi["geocodes"]["main"]["longitude"],
            "osm_url": OSM_ENDPOINT.format(poi["geocodes"]["main"]["latitude"], poi["geocodes"]["main"]["longitude"])
        }
        locations.append(loc)
        store_loc(loc)

    return locations
Powered by cgit v1.2.3 (git 2.41.0)