from functools import lru_cache

import requests
from urllib.parse import quote_plus
from pytz import timezone


LONG_LAT_URL = ('https://maps.googleapis.com/maps/api/geocode/json?address={0}'
                '&sensor=false')


@lru_cache(None)
def cached_json_get(url):
    """
    Makes a get to that URL and caches it. Simple right? Oh it also returns the
    JSON as a dict for you already!
    """
    return requests.get(url).json()


def get_tz(lat, lng):
    tzinfo = cached_json_get(
        'https://maps.googleapis.com/maps/api/timezone/json?location={0},'
        '{1}&timestamp=0'.format(
            lat, lng
        )
    )
    return timezone(tzinfo['timeZoneId'])


def whenareyou(address):
    latlong = cached_json_get(
        LONG_LAT_URL.format(quote_plus(address))
    )['results'][0]['geometry']['location']

    return get_tz(latlong['lat'], latlong['lng'])


if __name__ == '__main__':
    main()


@@ -1,12 +1,22 @@
+import os%0A
 from functoo
@@ -52,16 +52,27 @@
 equests%0A
+import csv%0A
 from url
@@ -241,16 +241,443 @@
 alse')%0A%0A
+airports_csv_path = os.path.join(os.path.dirname(__file__), 'airports.csv')%0A%0Aairports_dict = %7B%7D%0A%0Awith open(airports_csv_path) as csvfile:%0A    airports_reader = csv.DictReader(%0A        csvfile,%0A        fieldnames=%5B'id', 'name', 'city', 'country', 'iata', 'icao', 'lat',%0A                    'lng', 'alt', 'tz', 'dst', 'tz_olson'%5D,%0A        restkey='info')%0A    for row in airports_reader:%0A        airports_dict%5Brow%5B'iata'%5D%5D = row%0A%0A
 %0A@lru_ca
@@ -1326,16 +1326,103 @@
 ng'%5D)%0A%0A%0A
+def whenareyou_apt(airport):%0A    return timezone(airports_dict%5Bairport%5D%5B'tz_olson'%5D)%0A%0A%0A
 if __nam
@@ -1440,16 +1440,16 @@
 ain__':%0A
+
     main
@@ -1447,13 +1447,12 @@
 %0A    main()%0A
-%0A

Add airport timezone method