Weather Forecast API

weather-iconsThe aim of this challenge is to write a computer program to display a 5-day weather forecast for a specific location chosen by the end-user.

You program will:

  • retrieve the city from the end user (input),
  • Use the Open Weather Map API to retrieve an up-to-date weather forecast for this city,
  • parse the retrieved information,
  • display the 5-day weather forecast for the selected location. (output)

In order to do so you will use the Open Weather Map API: https://openweathermap.org/api

You will need to sign in to get an API key.

Then you will be able to make the relevant API calls such as the one described in the tabs below.

JSON or XML?


JSON and XML are two widely used choices for open data interchange.

Initially, XML (eXtensible Markup Language) was the only choice for open data interchange. But over the years the world of open data sharing has evolved a lot. The more lightweight JSON (JavaScript Object Notation) has become a popular alternative to XML for various reasons, one of the main reason being that JSON is more compact, faster and lighter (in terms of memory requirements) to process/parse.

The Open Weather Map API let you choose the format of the data to be retrieved using either the JSON format or XML format. (See examples provided below). So you will have to decide which format to use.

You can read and complete the following two challenges which demonstrate how to use a JSON API using Python code. These challenges will help you find out how to make an API call and how to parse a basic JSON data set.

Open Weather Map API


Here are a few examples of how to use the Open Weather Map API to retrieve JSON or XML data sets.

Current Weather - JSONCurrent Weather - XML5 Day Weather Forecast - JSON5 Day Weather Forecast - XML
API Call
Output

Find out more about date and time format using a UNIX Timestamp.

API Call

Output

Find out more about date and time format using a UNIX Timestamp.

This API generates the a weather forecast report for the next 5 days with a 3 hour interval.
API Call

Output

Find out more about date and time format using a UNIX Timestamp.

This API generates the a weather forecast report for the next 5 days with a 3 hour interval.
API Call

Output

Find out more about date and time format using a UNIX Timestamp.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 4

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , ,