YQL Weather statement not showing certain objects such as Sunrise, Sunset and Wind chill

StackOverflow https://stackoverflow.com/questions/16018339

  •  04-04-2022
  •  | 
  •  

Question

Hi there I am using the statement

    SELECT * FROM rss WHERE url="http://xml.weather.yahoo.com/forecastrss/SPXX0239_c.xml"

I get the data for a 5 day forecast, with date, icon, temp and text which is great. However I want to pull additional info such as wind chill, sunrise/sunset and feels like temp. I cannot see them in the request??

Here is my callback for the data

    window['wCallback_2'] = function(data) {
// Get todays weather forecast
     var info = data.query.results.item.forecast[0];
     var code = info.code;
$('#wData_current .wDate_d').append('<TD>' + info.date) + '</TD>';
    $('#wData_current .wDay_d').append('<TD>' + info.day) + '</TD>';
    $('#wData_current .wIcon_d').append('<TD> <img src="http://l.yimg.com/a/i/us/we/52/' + code + '.gif" width="80" height="80" title="' + info.text + '" /> </TD>');
$('#wData_current .wText_d').append('<TD>' + info.text + '</TD>');
    $('#wData_current .wHigh').append('<TD>' + info.high + '&deg;' + u + '</TD>');
    $('#wData_current .wLow').append('<TD>' + info.low + '&deg;' + u + '</TD>');

};

Était-ce utile?

La solution

The rss table only gives you what is inside the <item> element(s). Since RSS is plain old XML, the xml table can be used instead.

SELECT * FROM xml
WHERE url="http://xml.weather.yahoo.com/forecastrss/SPXX0239_c.xml"
AND itemPath="rss.channel.*"

Would give you a data object structured like:

{
 "query": {
  …
  "results": {
   "title": "Yahoo! Weather - Lanzarote, SP",
   …
   "location": { … },
   "units": { … },
   "wind": {
    "chill": "19",
    "direction": "20",
    "speed": "32.19"
   },
   "atmosphere": { … },
   "astronomy": {
    "sunrise": "7:29 am",
    "sunset": "8:19 pm"
   },
   "image": { … },
   "item": {
    "title": "Conditions for Lanzarote, SP at 8:59 pm WEST",
    "lat": "28.95",
    "long": "-13.6",
    "link": … ,
    "pubDate": "Mon, 15 Apr 2013 8:59 pm WEST",
    "condition": { … },
    "description": … ,
    "forecast": [ … ],
    "guid": { … }
   }
  }
 }
}

To access the sunrise time, you could use data.query.results.astronomy.sunrise.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top