Chose the API



The mechanism is finished, and it is time to choose the weather API. I wanted the display to update the weather info every half hour.

There are lots of services in a global web announcing the weather: AccuWeather, Forecast.io, AerisWeather, OpenWeatherMap, WeatherBug, World Weather Online, e.t.c.

I chose the AccuWeather API. It has a user-friendly interface and precise documentation. It can show the weather all over the planet and almost in any city. However, it is not free. The limited but free trial for a single API key is 50 calls/day. It is enough for a half hour updates.

Obtain a Key

1. Register at the Web site. Check your e-mail box. Edit your profile and log in to the site.

2. Press "My apps" and create a new Weather App. Name the app. Set the place where the API is used to "Other" and choose the C++ programming language.

3. Open "My apps" then open the app you created and get the API Key.

It looks like (this key is not real):

UrWtYw3y5A8DaFcJfMhQmSpUsXuZw4z6B8E

Write it down and save somewhere on your computer. Do not give this key to anyone.

Find out the city ID

You should know the ID of the city in which you want to know the weather. I live in Moscow, so I needed the Moscow city ID.

1. Go to "API Reference" -> "Location API".

2. As Moscow is one of the biggest cities I choose "List -> GET -> Top Cities List".

3. Enter the number of cities at the "Resource URL".

4. Enter your API key to the "Query Parameters".

5. Send request.

6. Find an ID of the necessary city in the response.

"Version": 1, "Key": "294021", "Type": "City", "Rank": 10, "LocalizedName": "Moscow", "EnglishName": "Moscow", "PrimaryPostalCode": "", "Region": { "ID": "ASI", "LocalizedName": "Asia", "EnglishName": "Asia"

7. The Moscow ID is 294021. Write down your ID somewhere not to forget.

Test the API

Let's test the API before we use it in the XOD environment and get the current weather in Moscow.

1. Go to "API Reference" -> "Forecast API" -> "1 Hour of Hourly Forecasts".

2. Enter the city ID into the "Resource URL". For my example the URL looks like:

http://dataservice.accuweather.com/forecasts/v1/hourly/1hour/294021

3. Enter the "Query Parameters" and send the request.

4. If you do everything right, you'll get something like this in the response:

"DateTime": "2018-08-03T18:00:00+03:00", "EpochDateTime": 1533308400, "WeatherIcon": 2, "IconPhrase": "Mostly sunny", "IsDaylight": true, "Temperature": { "Value": 27.6, "Unit": "C", "UnitType": 17

That's the information we will work with in XOD.