1

I am building a web app, which uses Yahoo Weather API to provide weather information, based on a ZIP code, provided by the users.

I know that in order to obtain this data for certain number of days I have to add it as a parameter in my request, like so:

http://weather.yahooapis.com/forecastrss?p=33035&u=c&d=3

Which gives this result:

<channel>
....
<yweather:location city="Homestead" region="FL" country="US"/>
<yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
<yweather:wind chill="19" direction="90" speed="11.27"/>
<yweather:atmosphere humidity="78" visibility="16.09" pressure="1021" rising="1"/>
<yweather:astronomy sunrise="7:12 am" sunset="7:36 pm"/>
...
<item>
...
<yweather:forecast day="Wed" date="2 Apr 2014" low="19" high="28" text="Mostly Sunny" code="34"/>
<yweather:forecast day="Thu" date="3 Apr 2014" low="21" high="29" text="Partly Cloudy" code="30"/>
<yweather:forecast day="Fri" date="4 Apr 2014" low="20" high="28" text="Partly Cloudy" code="30"/>
<guid isPermaLink="false">USFL0208_2014_04_04_7_00_EDT</guid>
</item>
</channel>

However I need to be able to get the humidity level for EVERY day in the forecast and not just the current one. I've tried to find solution here and also read the Yahoo API documentation, but it's really a short one.

I've also tried http://www.myweather2.com/ and http://developer.worldweatheronline.com/, but they have the same issue with humidity - it's shown only for the current day and stripped from the whole forecast.

I'll keep trying with other free Weather APIs, but if you can help here I'd be very grateful.

Nat Naydenova
  • 771
  • 2
  • 12
  • 30

1 Answers1

1

I've spent some time researching for better APIs than the Yahoo! Weather API and I found something, that works for me, so I've decided to share the info, in case anyone else bump into this some day.

Version 2 of the Forecast API looks like a nice solution, because it provides detailed information, more specifically the humidity index for each day in the forecast, which was what I was looking for in the first place. There are also number of libraries for this API (languages include PHP, Node.js, Python, Perl and others).

It works with longitude & latitude as in this example

https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME

and of course one needs to register for an API key.
The TIME parameter is optional, the temperature uses Fahrenheit metrics by default, but this can be changed with additional ?units=ca parameter.

One disadvantage is that you get only a 1,000 free calls per day, which probably won't be suitable for big applications.

If you know a better answer to the original question, I'll be very happy to hear it. Until then I'll use this solution, without going into much details:

// The default result from a Forecast API call is in JSON,
// so decode it to an object for easier access
$fcObj = json_decode($jsonResult);

if(!empty($fcObj->daily->data[0]->humidity)) {

    // get humidity value in %
    $humidty = $fcObj->daily->data[0]->humidity * 100;

}
Nat Naydenova
  • 771
  • 2
  • 12
  • 30
  • Can you pls let me know that the wind value is in km/h and the temperature is Celsius? I am also using yahoo weather API but just confuse in their units – Chandni Jan 15 '21 at 11:34