Time Zone Process Flow

getTimeZone flow is consists of the following steps.
  • Identify the City Name using from raw speech communicated by Human
  • Get the Latitude and Longitude of the City Name.
  • Get the Time Zone
places = geograpy.get_geoPlace_context(text=rawspeech)
city_name = GetCityName(places)
LatitudeValue,LongitudeValue = geoLocateLatitudeLongitude(city_name)
timeZone = getTimeZoneValue(LatitudeValue, LongitudeValue)

Once the getTimeZone flow is triggered raw speech is passed to geography package geoPlace Function to identify the place from the raw speech.
places = geograpy.get_geoPlace_context(text=rawspeech)
city_name = GetCityName(places)
Once the location is identified, GetCityName flow is used to get the name of the city from places list. First occurrence of the city is selected.
In case of no city identified, an exception is raised and is handled by defaulting the city to home city.
city_name = places.cities[0]
return city_name
except Exception as e:
city_name = homeCityName
return city_name
geograpy extracts place names from a URL or text, and adds context to those names -- for example distinguishing between a country, region or city.
The extraction is a two step process.
  • The first process is a Natural Language Processing task which analyzes a text for potential mentions of geographic locations.
  • In the next step the words which represent such locations are looked up using the Locator.
If you already know that your content has geographic information you might want to use the Locator interface directly.

geoLocateLatitudeLongitude flow is executed to Identify the Latitude and Longitude, City Name is passed to geopy package to identify the Latitude and Longitude of the given City.
geopy makes it easy for Python developers to locate the coordinates of addresses, cities, countries, and landmarks across the globe using third-party geocoders and other data sources.
geopy includes geocoder classes for the OpenStreetMap Nominatim, Google Geocoding API (V3), and many other geocoding services.
How it works using geopy?
  • Once geopy package is installed.
  • Import Nominatim from geopy- Nominatim is a free service or tool or can be called as API with no keys that provides you with the data after providing it with name and address and vice versa.
  • On calling Nomination tool which accepts an argument of user_agent you can give any name as it considers it to be the name of the app to which it is providing its services. Here we are using user_agent Name as Aryan.
  • The geocode() function accepts the location name and returns a geodataframe that has all the details and since it’s a dataframe we can get the address, latitude and longitude by simply calling it as in snippet below.
geolocator = Nominatim(user_agent="Aryan")
LatitudeValue = geolocator.geocode(city_name).latitude
LongitudeValue = geolocator.geocode(city_name).longitude

Once Latitude and Longitude are Identified getTimeZoneValue flow is executed and using tzwhere package time zone is identified and returned to the user for the requested place
timezoneobject = tzwhere.tzwhere()
timezone = timezoneobject.tzNameAt(LatitudeValue, LongitudeValue)
tzwhere is a Python library to lookup the timezone for a given Latitude and Longitude entirely offline.
Time Zone is returned to the user and Control passed to NextStep.
Copy link
On this page
Overall Flow
Identify the City Name
Identify Latitude and Longitude
Get Time Zone using Latitude and Longitude