Walkero

software engineer, Drupal follower, Docker ninja, JS explorer, PHP believer, exotic Hardware beta tester, Amiga enthusiast, truth seeker, parent & husband... at least for now...

Yahoo Weather API is a great weather condition source, which you can use on your apps free of charge. Many apps use it, like the StormCloud, Drupal and Joomla modules and many applications for smart phones. The iOS main weather application retrieves weather condition from Yahoo too.

But how can you use it to your applications and retrieve forecast for 5 days?

--more--

The place I live is called Agia Paraskevi, which is in Athens - Greece, and I will use it as an example at the following codes. The Yahoo weather API exchange data using the RSS and XML formats. So, you have to be familiar with these formats to use it. To get the info you need you have only to request data using specific URLs and parameters.

The first thing we need is to find the place WOEID, which is a unique ID number. To get this you have to access the URL http://query.yahooapis.com/v1/public/yql with two parameters, the q which is an SQL query that includes your living town name, and the format which we set to xml. Have in mind that the URL should be encoded as one, before you access it.

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Agia%20Paraskevi%20Greece,%20Athens%22&format=xml

The above url will return an XML page where we can find the WOEID at the first data child and under the tag:

24544198

Among other info we can get the name of the place as Yahoo provides it, under the tag

Agia Paraskevi

So, we have now the WOEID of our place of living. Using this we can get the weather condition by accessing the following URL. The w parameter is the WOEID number.

http://weather.yahooapis.com/forecastrss?w=24544198

The return data from the above URL is an RSS with the place weather condition and a forecast for 2 days. So you have now your basic weather condition info.

But how can you get a forecast for 5 days?

If we would like to get more than 2 days forecast, we first have to find the global zip code (GUID) of the place. This can be found at the end of the previous RSS result, with the tag:

GRXX0012_2013_05_16_7_00_EEST

Using the GUID “GRXX0012” and the following URL we can get 5 days forecast, in RSS format again. The _c extension at the URL will return the degrees in Celsius unit, but the _f in Fahrenheit unit.

http://xml.weather.yahoo.com/forecastrss/GRXX0012_c.xml

That’s all you have to do to get the weather condition info. This can be used with any programming language you like.

#yahoo #weather #API
- 2 min read