예제 #1
0
def add_altitudes(stations, size=50):
    ''' Use the Google Maps Elevation API. '''
    base = 'https://maps.googleapis.com/maps/api/elevation/json?'
    key = tools.read_json('config/keys.json')['google-elevation']
    locationsList = ''
    packages = []
    counter = 1
    for station in stations:
        locationsList += '{lat},{lon}|'.format(lat=station['lat'],
                                               lon=station['lon'])
        # The API only allows a certain amount of locations per request
        counter += 1
        if counter > size:
            locationsList += ';'
            counter = 1
    for locations in locationsList.split(';'):
        locations = locations[:-1]
        url = base + 'locations={0}&key={1}'.format(locations, key)
        request = tools.query_API(url)
        data = tools.load_json(request)
        packages.append(data['results'])
    # Melt the packages into one list
    altitudes = []
    for package in packages:
        altitudes.extend(package)
    # Tidy everything up for database insertion
    data = []
    for station in zip(stations, altitudes):
        data.append({
            'name': station[0]['name'],
            'lat': station[0]['lat'],
            'lon': station[0]['lon'],
            'alt': station[1]['elevation']
        })
    return data
예제 #2
0
def stations(city):
    base = 'https://api.jcdecaux.com/vls/v1/'
    key = tools.read_json('config/keys.json')['jcdecaux']
    url = '{0}stations/?contract={1}&apiKey={2}'.format(base, city, key)
    data = tools.query_API(url)
    stations = tools.load_json(data)
    return normalize(stations)
예제 #3
0
def add_altitudes(stations, size=50):
    ''' Use the Google Maps Elevation API. '''
    base = 'https://maps.googleapis.com/maps/api/elevation/json?'
    key = tools.read_json('config/keys.json')['google-elevation']
    locationsList = ''
    packages = []
    counter = 1
    for station in stations:
        locationsList += '{lat},{lon}|'.format(lat=station['lat'],
                                               lon=station['lon'])
        # The API only allows a certain amount of locations per request
        counter += 1
        if counter > size:
            locationsList += ';'
            counter = 1
    for locations in locationsList.split(';'):
        locations = locations[:-1]
        url = base + 'locations={0}&key={1}'.format(locations, key)
        request = tools.query_API(url)
        data = tools.load_json(request)
        packages.append(data['results'])
    # Melt the packages into one list
    altitudes = []
    for package in packages:
        altitudes.extend(package)
    # Tidy everything up for database insertion
    data = []
    for station in zip(stations, altitudes):
        data.append({
            'name': station[0]['name'],
            'lat': station[0]['lat'],
            'lon': station[0]['lon'],
            'alt': station[1]['elevation']
        })
    return data
예제 #4
0
def stations(city):
    # The city parameter is necessary so that everything works
    base = 'http://data.keolis-rennes.com/json/?version=1.0&'
    key = tools.read_json('config/keys.json')['keolis']
    url = '{0}key={1}&cmd=getstation'.format(base, key)
    data = tools.query_API(url)
    stations = tools.load_json(data)
    return normalize(stations)
예제 #5
0
def stations(city):
    # The city parameter is necessary so that everything works
    base = 'http://data.keolis-rennes.com/json/?version=1.0&'
    key = tools.read_json('config/keys.json')['keolis']
    url = '{0}key={1}&cmd=getstation'.format(base, key)
    data = tools.query_API(url)
    stations = tools.load_json(data)
    return normalize(stations)
예제 #6
0
파일: bixi.py 프로젝트: gitthinkoo/Website
def stations(city):
    designations = {
        'Toronto': 'toronto',
        'Montréal': 'montreal',
        'Ottawa': 'capitale'
    }
    designation = designations[city]
    url = 'https://{}.bixi.com/data/bikeStations.xml'.format(designation)
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #7
0
def stations(city):
    designations = {
        'Toronto': 'toronto',
        'Montréal': 'montreal',
        'Ottawa': 'capitale'
    }
    designation = designations[city]
    url = 'https://{}.bixi.com/data/bikeStations.xml'.format(designation)
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #8
0
def stations(city):
    # The city parameter is necessary so that everything works
    key = tools.read_json('config/keys.json')['lacub']
    url = 'http://data.lacub.fr/wfs?key={}' \
          '&SERVICE=WFS&VERSION=1.1.0&' \
          'REQUEST=GetFeature' \
          '&TYPENAME=CI_VCUB_P&SRSNAME=EPSG:4326'
    print(url)
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    print(stations)
    return normalize(stations)
예제 #9
0
파일: lacub.py 프로젝트: gitthinkoo/Website
def stations(city):
    # The city parameter is necessary so that everything works
    key = tools.read_json('config/keys.json')['lacub']
    url = 'http://data.lacub.fr/wfs?key={}' \
          '&SERVICE=WFS&VERSION=1.1.0&' \
          'REQUEST=GetFeature' \
          '&TYPENAME=CI_VCUB_P&SRSNAME=EPSG:4326'
    print(url)
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    print(stations)
    return normalize(stations)
예제 #10
0
def geocode(address):
    '''
    Return the latitude and longitude of an address
    thanks to the Nominatim API.
    '''
    base = 'http://nominatim.openstreetmap.org/search?' \
           'format=json&polygon_geojson=1&q='
    text = tools.remove_special_characters(address)
    keywords = '+'.join(text.split())
    url = ''.join((base, keywords))
    data = tools.query_API(url)
    address = tools.load_json(data)[0]
    latitude = float(address['lat'])
    longitude = float(address['lon'])
    return (latitude, longitude)
예제 #11
0
def geocode(address):
    '''
    Return the latitude and longitude of an address
    thanks to the Nominatim API.
    '''
    base = 'http://nominatim.openstreetmap.org/search?' \
           'format=json&polygon_geojson=1&q='
    text = tools.remove_special_characters(address)
    keywords = '+'.join(text.split())
    url = ''.join((base, keywords))
    data = tools.query_API(url)
    address = tools.load_json(data)[0]
    latitude = float(address['lat'])
    longitude = float(address['lon'])
    return (latitude, longitude)
예제 #12
0
def compute_distances(departure, stations, mode):
    ''' Using the Mapbox Distance API. '''
    # Interrogate the API to get the distance to each station
    base = 'https://api.mapbox.com/distances/v1/mapbox/'
    key = tools.read_json('config/keys.json')['mapbox-distance']
    coordinates = {
        'coordinates': [departure] + [station['p'] for station in stations]
    }
    print(coordinates)
    url = '{0}{1}?access_token={2}'.format(base, mode, key)
    data = tools.query_API(url)
    distances = tools.load_json(data)['rows'][0]['elements']
    candidates = []
    for station in zip(stations, distances):
        candidate = {}
        for information in station:
            candidate.update(information)
        candidates.append(candidate)
    return candidates
예제 #13
0
def compute_distances(departure, stations, mode):
    ''' Using the Mapbox Distance API. '''
    # Interrogate the API to get the distance to each station
    base = 'https://api.mapbox.com/distances/v1/mapbox/'
    key = tools.read_json('config/keys.json')['mapbox-distance']
    coordinates = {
        'coordinates': [
            departure
        ] + [station['p'] for station in stations]
    }
    print(coordinates)
    url = '{0}{1}?access_token={2}'.format(base, mode, key)
    data = tools.query_API(url)
    distances = tools.load_json(data)['rows'][0]['elements']
    candidates = []
    for station in zip(stations, distances):
        candidate = {}
        for information in station:
            candidate.update(information)
        candidates.append(candidate)
    return candidates
예제 #14
0
def get_route(url):
    ''' Specific function to perform caching. '''
    data = tools.query_API(url, repeat=True)
    return data
예제 #15
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'https://secure.niceridemn.org/data2/bikeStations.xml'
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #16
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'https://tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml'
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #17
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'https://www.capitalbikeshare.com/data/stations/bikeStations.xml'
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #18
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'https://secure.niceridemn.org/data2/bikeStations.xml'
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #19
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'http://minaport.ubweb.jp/stations.php'
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #20
0
def get_route(url):
    ''' Specific function to perform caching. '''
    data = tools.query_API(url, repeat=True)
    return data
예제 #21
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'http://www.bikechattanooga.com/stations/json'
    data = tools.query_API(url)
    stations = tools.load_json(data)
    return normalize(stations)
예제 #22
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'https://www.capitalbikeshare.com/data/stations/bikeStations.xml'
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)
예제 #23
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'http://minaport.ubweb.jp/stations.php'
    data = tools.query_API(url)
    stations = tools.load_xml(data)
    return normalize(stations)