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.
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.
try:
city_name = places.cities[0]
return city_name
except Exception as e:
city_name = homeCityName
return city_name
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.
#Enter your openwathermap API key here
api_key = openweathermap_apikey
#base_url variable to store url
base_url = "http://api.openweathermap.org/data/2.5/weather?"
# complete_url variable to store complete url address
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
# get method of requests module return response object
response = requests.get(complete_url)
# json method of response object convert json format data into python format data
data = response.json()
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
main = data["main"]
current_temperature = main["temp"]
report = data["weather"]
weather_description = report[0]["description"]
Last updated
Was this helpful?