Part 4 - Weather Skill
Lets build our next skill - get the weather forecast for our location
Overview
In this part we will create a useful Weather Skill - to get the forecast for the next 5 days as well as todays weather. Weβll use a cloud based weather service (no pun intended, wellβ¦).
Table of Contents
- Overview
- Table of Contents
- Video on YouTube
- Session Goals
- Build a Weather skill
- OpenWeather Map
- PyOWM
- Our Weather Class
- Code
Video on YouTube
I created a popular video series on YouTube, which goes over each of the steps below. The fourth part is featured below.
Session Goals
Build a Weather Skill OpenWeatherMap PyOWM Library Python Code
Build a Weather skill
- Get weather forecast for next 5 days
- Get todays weather
- Look at the types of data we can pull from Open Weather Map
- Speak the forecast on command
OpenWeather Map
Where we get our weather data from OpenWeather
- Create a free account on OpenWeather
- Create an API key (weβll need this to access the weather data in our code)
PyOWM
Python OpenWeatherMap Library
PyOWM makes it easy to get a weather forecast Use βone_callβ with lat and long and it will return a weather object containing lots of data we can use
def weather(self):
""" Returns the current weather at this location """
forecast = self.mgr.one_call(lat=self.lat, lon=self.long)
return forecast
Latitude and Longitude
Whereβs you at?
- OpenWeatherMap takes a Lat and Long position
- We can get this using GeoPy - a Python Geographic Utility Library
- Geopy can take a place name and country and provide the lat and long of this location
- We can then use the Lat and Long to get the weather forecast
Our Weather Class
What weβre aiming for
AI will say:
Here is todayβs weather: Today will be mostly
, with a temperature of , humidity of , and a pressure of millibars. Sunrise was at , and sunset is at . The Ultaviolet level is
Comments