Example #1
0
def stations(city):
    base = 'https://api.jcdecaux.com/vls/v1/'
    key = keys['jcdecaux']
    url = '{0}stations/?contract={1}&apiKey={2}'.format(base, city, key)
    data = tb.query_API(url)
    stations = tb.load_json(data)
    return normalize(stations)
Example #2
0
def stations(city):
    # The city parameter is necessary so that everything works
    base = 'http://data.keolis-rennes.com/json/?version=1.0&'
    key = keys['keolis']
    url = '{0}key={1}&cmd=getstation'.format(base, key)
    data = tb.query_API(url)
    stations = tb.load_json(data)
    return normalize(stations)
Example #3
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 = tb.remove_special_characters(address)
    keywords = '+'.join(text.split())
    url = ''.join((base, keywords))
    data = tb.query_API(url)
    address = tb.load_json(data)[0]
    latitude = float(address['lat'])
    longitude = float(address['lon'])
    return (latitude, longitude)
Example #4
0
def turn_by_turn(trip):
    """ Build a path using the Google Directions API. """
    mode = trip["mode"]
    points = ["{0},{1}".format(point["lat"], point["lon"]) for point in trip["points"]]
    origin = points[0]
    destination = points[1]
    base = "https://maps.googleapis.com/maps/api/directions/json"
    key = tb.read_json("common/keys.json")["google-distance"]
    url = "{0}?origin={1}&destination={2}&mode={3}&key={4}".format(base, origin, destination, "walking", key)
    # Query the API
    response = get_route(url)
    trip = tb.load_json(response)
    return {
        "mode": mode,
        "routes": trip["routes"][0]["legs"][0]["steps"],
        "polyline": trip["routes"][0]["overview_polyline"]["points"],
    }
Example #5
0
def add(stations, size=50):
    '''
    Use the Google Maps Elevation API to add altitudes to a dataframe.
    Because the API has a limitation this function batches the work into
    "packages" that are successively send to the API. The size parameter
    determines the size of the packages. The function starts by looping
    through the stations and increments a counter. Once the counter has
    reached the package size then it sends a request to the API and resets the
    counter. Once it has parsed all the stations it unwraps what the API
    send back into a list of dictionaries and sends it back.
    '''
    base = 'https://maps.googleapis.com/maps/api/elevation/json?'
    key = tb.read_json('common/keys.json')['google-elevation']
    locations = ''
    packages = []
    counter = 1
    for station in stations:
        locations += '{lat},{lon}|'.format(lat=station['lat'],
                                           lon=station['lon'])
        counter += 1
        if counter > size:
            locations += ';'
            counter = 1
    for loc in locations.split(';'):
        url = base + 'locations={0}&key={1}'.format(loc[:-1], key)
        request = tb.query_API(url)
        data = tb.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 = [{'name': station[0]['name'], 'lat': station[0]['lat'],
            'lon': station[0]['lon'], 'alt': station[1]['elevation']}
            for station in zip(stations, altitudes)]
    return data
Example #6
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'http://www.bikechattanooga.com/stations/json'
    data = tb.query_API(url)
    stations = tb.load_json(data)
    return normalize(stations)
Example #7
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = "http://www.bayareabikeshare.com/stations/json"
    data = tb.query_API(url)
    stations = tb.load_json(data)
    return normalize(stations)