def get_tz(location): cache = Cache() if location is None: return None timezone = cache.timezone_cached(location) if timezone: return timezone try: place, (lat, lng) = geo.geocode(location, timeout=10) except GeocoderTimedOut as e: print("Error: geocode failed on input %s with message %s" % (location, e.message)) return None except TypeError: return None tz = geo.timezone((lat, lng)) timezone = tz.zone cache.save_to_cache(location, timezone) return timezone