Пример #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)
Пример #2
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 = tb.query_API(url)
    stations = tb.load_xml(data)
    return normalize(stations)
Пример #3
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)
Пример #4
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 = tb.query_API(url)
    stations = tb.load_xml(data)
    return normalize(stations)
Пример #5
0
def stations(city):
    # The city parameter is necessary so that everything works
    key = keys["lacub"]
    url = (
        "http://data.lacub.fr/wfs?key={}"
        "&SERVICE=WFS&VERSION=1.1.0&"
        "REQUEST=GetFeature"
        "&TYPENAME=CI_VCUB_P&SRSNAME=EPSG:4326"
    )
    data = tb.query_API(url)
    stations = tb.load_xml(data)
    return normalize(stations)
Пример #6
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)
Пример #7
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
Пример #8
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)
Пример #9
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = "http://minaport.ubweb.jp/stations.php"
    data = tb.query_API(url)
    stations = tb.load_xml(data)
    return normalize(stations)
Пример #10
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'https://secure.niceridemn.org/data2/bikeStations.xml'
    data = tb.query_API(url)
    stations = tb.load_xml(data)
    return normalize(stations)
Пример #11
0
def get_route(url):
    """ Specific function to perform caching. """
    response = tb.query_API(url)
    return response
Пример #12
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)
Пример #13
0
def stations(city):
    # The city parameter is necessary so that everything works
    url = 'http://www.thehubway.com/data/stations/bikeStations.xml'
    data = tb.query_API(url)
    stations = tb.load_xml(data)
    return normalize(stations)