🌐Get weather
Learn how Misty can interact with the Web, request data and analyze them!
In this project, Misty will use the command send_external request to connect with Weatherstack and request your city's data.
In the first lines of Misty's code, we import the usual libraries and the JSON one.
We need to import this library because the data from Weatherstack are sent in that format.
After initializing the Misty robot and the other variables, like the access_key and the query we run the misty.send_external_request command that will use the GET method to request the weather data in your city.
The following statement tests if the request succeeded and if yes proceeds to organize the data and assign the value to the variables that you'll use in your Misty's animations. Otherwise, you'll get an error message and Misty's skill will finish.
Weatherstack key
Weatherstack is an online weather data API service that provides real-time weather information, historical data, and weather forecasts for various locations around the world. It is commonly used by developers to integrate weather data into applications and websites. The service is known for its reliability, ease of use, and wide coverage, making it popular for various weather-based applications and projects.
Navigate in Weatherstack
Click on "START USING THE API"
Sign up with your credentials and your plan (we used the free version, which gives only 250 API requests)
Click on "VISIT DASHBOARD"
and you'll see your API Key with many other information.
Weatherstack data
In this example, we requested the weather in Stockholm.
There are three main areas:
request: contains the information about your request
location: contains the information about your location like the name of the city, latitude, longitude and local time when the request was sent
current: contains the information about the weather in your city like temperature, weather descriptions, wind details, humidity and many more data
You can refer to the data in Python in this way:
If you want to extrapolate the weather description, that's an array, you can refer to the position index for that element. In this case, the weather description has only one element in the array so we'll refer to the first element (position index = 0)
weather_descriptions = parsed["current"]["weather_descriptions"][0]
Last updated