Weather Process Flow

Identify the City Name

"Aryan, Can you tell me Weather of New York?" Once the weather flow is triggered raw speech is passed to geography package geoPlace Function to identify the place from the raw speech.
1
places = geograpy.get_geoPlace_context(text=rawspeech)
2
city_name = GetCityName(places)
Copied!
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.
geograpy3 uses the following excellent libraries:
  • NLTK for entity recognition
  • newspaper for text extraction from HTML
  • jellyfish for fuzzy text match
  • pylodstorage for storage and retrieval of tabular data from SQL and SPARQL sources
geograpy3 uses the following data sources:
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.
1
try:
2
city_name = places.cities[0]
3
return city_name
4
except Exception as e:
5
city_name = homeCityName
6
return city_name
Copied!

Get the Weather Details for the City

Once you get the city name, next step is to use the city to have a API call to openweathermap using the pre-defined API key to get the current weather information.
Response of API is captured in JSON dump for further parsing.
API calls to OpenWeatherMap is used by Aryan to source the weather information, it allows Aryan to
  • Access current weather data for any location including over 200,000 cities
  • The weather data is collected from different sources such as global and local weather models, satellites, radars and a vast network of weather stations
1
#Enter your openwathermap API key here
2
api_key = openweathermap_apikey
3
4
#base_url variable to store url
5
base_url = "http://api.openweathermap.org/data/2.5/weather?"
6
7
# complete_url variable to store complete url address
8
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
9
10
# get method of requests module return response object
11
response = requests.get(complete_url)
12
13
# json method of response object convert json format data into python format data
14
data = response.json()
Copied!

Get the Weather Description and Temperature

Once the JSON Dump is received, Aryan parses the JSON file which is enriched with weather information to get the temperature and weather description. This real time information is then provided to Human
1
main = data["main"]
2
current_temperature = main["temp"]
3
report = data["weather"]
4
weather_description = report[0]["description"]
Copied!