Exemplo n.º 1
0
def get_latlng(location):
    cache = FileCache('uber-button-cache')

    if location not in cache:
        geolocator = Nominatim(user_agent="Uber-Button")
        geolocator.timeout = 60
        time.sleep(1.1)
        cache[location] = geolocator.geocode(location)
        cache.sync()

    return cache[location]
Exemplo n.º 2
0
df_citywise = df_citywise.iloc[:, :-3]

df_citywise['TOTAL TRAFFIC'] = df_citywise[
    'PASSENGERS FROM CITY1 TO CITY2'] + df_citywise[
        'PASSENGERS FROM CITY2 TO CITY1']

df_citywise_cumulative_traffic = df_citywise.groupby(
    ['CITY1', 'CITY2'])['TOTAL TRAFFIC'].sum().reset_index()

AVG_PASSENGERS_PER_FLIGHT = 240
df_citywise_cumulative_traffic['nb_flights'] = round(
    df_citywise_cumulative_traffic['TOTAL TRAFFIC'] /
    AVG_PASSENGERS_PER_FLIGHT)

geolocator = Nominatim()
geolocator.timeout = 180

location = geolocator.geocode("ABUDHABI")
print(str(location.latitude) + ', ' + str(location.longitude))
print(df_citywise_cumulative_traffic.head(10))

location_dict = {}

dep_cities = df_citywise_cumulative_traffic['CITY1'].unique()
dep_cities = np.append(dep_cities,
                       df_citywise_cumulative_traffic['CITY2'].unique())

for dep_city in dep_cities:
    print('Geocoding - ' + dep_city)
    location = geolocator.geocode(dep_city)
    if location is not None: