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)

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.

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.

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

#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