Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Demonstration of API using OpenWeatherMap.org

This demonstration is heavily inspired by NeuralNine’s video.
You need a free account from here.
The VS Code extension JSON viewer is recommended for viewing downloaded JSON content.

  • Set your maximum API calls to 1000 per day to make sure you are under the limit for billing.

  • To run the examples, download your API key, save it in the right folder (see below) in a file called api_key_OpenWeather, containing only the key (no spaces or “enters”).

Current weather

Common definitions to use for all requests

Request current weather in chosen city

Conversion functions

Changing scales can make results more interpretable

Forecasted weather

Common definitions to use for all requests

Request forecasted weather in chosen city

When and what?

Check contents and time stamps

Make plots of omnipresent measurements and events

We will later look at missing data, data only sporadically appearing and so on.

Exercise

  • Make a new forecast request for your own hometown. Call your response something else than responseF.

  • If available, plot the humidity like we did with air pressure.

Precipitation

  • ... comes in two main flavours: rain and snow.

  • We need to check which is present and set to zero if it is abscent.

Live coding

  • Create a Streamlit app with these elements:

    • City selector (can we make use of the Geocoding API?)

    • Property selector

    • Print selected data