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


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)

https://openweathermap.org/


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


Code

Did you find this content useful?


If you found this high quality content useful please consider supporting my work, so I can continue to create more content for you.

I give away all my content for free: Weekly video content on YouTube, 3d Printable designs, Programs and Code, Reviews and Project write-ups, but 98% of visitors don't give back, they simply read/watch, download and go. If everyone who reads or watches my content, who likes it, helps fund it just a little, my future would be more secure for years to come. A price of a cup of coffee is all I ask.

There are a couple of ways you can support my work financially:


If you can't afford to provide any financial support, you can also help me grow my influence by doing the following:


Thank you again for your support and helping me grow my hobby into a business I can sustain.
- Kevin McAleer