Yahoo weather API, randomly returns old data?
Asked Answered
G

3

10

I started using Yahoo's free weather API to get the weather data I need, but it seems each time I request a city weather data there is a chance that either I get updated data or old data from back to 1 to 8 days.

Here is a simple URL which I make my request with: Click here to see a sample request

The YQL query is simple, which requests the weather data for New York city:

select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="New York")

But each time I refresh that URL, I might get a completely different result. for example I did refresh it right now a couple times (Now is 13th of November 2015, around 22:45 GMT time) and here are some results I got in the query.results.channel.item.condition.date part:

"date":"Fri, 13 Nov 2015 4:49 pm EST"
"date":"Thu, 12 Nov 2015 2:13 am EST"
"date":"Wed, 11 Nov 2015 1:49 am EST"
"date":"Fri, 13 Nov 2015 1:49 am EST"

This is very wired, how am I supposed to get current weather data like this when the API returns weather data for random dates each time I make a request?

Am I doing something wrong or missing something here?

Notes:

  • This behavior is same for many different cities which I tried.
  • Using same query in YQL Console doesn't seem to be having same problem. (YQL Console) (Actually same problem has been spotted there too)
  • Same thing is also happening on this XML/RSS request method as well: http://weather.yahooapis.com/forecastrss?w=2459115

Updates:

  • I did come across a case which returned me data from 8 days back!
  • Using SORT functions of YQL doesn't fix the problem, since the sort is applied after selecting requested record/records.
  • Today (25th of November 2015), I have tried more than 20 refreshes and seems the data returning is always correct, it seems the problem is fixed.

  • On 26th of November 2015 Yahoo announced that the problem is fixed: Thanks for your feedback. This issue has been fixed. Please check out the site again. If you are still having this problem, please post a new idea on this forum.

Guadiana answered 13/11, 2015 at 22:49 Comment(4)
It's been almost a month, and no action from Yahoo. My solution below seems to work quite well and I have been tested it for over 20 days. The code is a complete JavaScript implementation. I agree, calling it repeatedly is not efficient, but it's the best we've got. Most of the times it returns within 5 tries. Once in a great while it goes beyond 15 tries.Broussard
@Vijay Jagdale: This problem is already fixed by Yahoo, please note the update I added on 26th of November: On 26th of November 2015 Yahoo announced that the problem is fixed: Thanks for your feedback. This issue has been fixed. Please check out the site again. If you are still having this problem, please post a new idea on this forum.Guadiana
PS: I have voted twice to close this question, but seems there aren't enough votes. I believe this should be closed with no accepted answer since the problem was a bug from Yahoo's side which is fixed already, not a programming mistake.Guadiana
Actually it started behaving a lot better only since a few days back. But it is not completely fixed. If you run my code below it tells you how many round trips it needed to get to the correct data, and it still seems like it returns stale data half of the time, and needs a second trip.Broussard
E
3

Yahoo dev's replied on twitter saying that they are investigating this issue. You can follow it up and upvote (for speeding the process) it here:

https://yahoo.uservoice.com/forums/207813/suggestions/10740099

Empty answered 21/11, 2015 at 0:51 Comment(0)
Z
2

I have used the Yahoo Weather API XML format for years and noticed in that last couple of weeks this new bug. I tried to report the bug to https://developer.yahoo.com/weather/support but get a 404 page not found. I decided to parse the returned date if equal to current date to continue if not equal to re-call sub. this way I always get current weather but unfortunately that's a lot of unnecessary traffic / request maybe YDN will realize and fix. but without being able to report I don't know. I know this is not a fix but more a Band-Aid good luck!

Private Sub btnWeather_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeather.Click

    If InternetConnection() = False Then
        MsgBox("No internet connection!", vbExclamation, "Oops!")
        Exit Sub
    Else

        'MsgBox("Internet connection detected!", vbInformation, "Huray!")

        btnWeather.Enabled = False
        lblWorking.Text = "Working ..."
        tbTries.Text = "1"

        Try

            Dim t As New clsWeather(Format(Me.TxtBoxZIP.Text), "f")
            lblTodaysDate.Text = FormatDateTime(Now.Date, DateFormat.ShortDate)
            tbHigh.Text = t.high & "°"
            lblCity.Text = TxtBoxZIP.Text & " Weather "
            tbLow.Text = t.Low & "°"
            tbDay.Text = t.day
            tbDate.Text = t.date1
            tbCurrenttemp.Text = t.currenttemp & "°"
            tbCurrentCode.Text = t.currentcode
            tbForcastCode.Text = t.ForcastCode
            tbSunrise.Text = t.Sunrise
            tbSunset.Text = t.Sunset
            tbWind.Text = CInt(Val(t.Wind)) & " mph"
            tbHumidity.Text = CInt(Val(t.humidity))
            imgWeather.Image = Image.FromFile(t.GetImage)
            CodeName()


            If t.currenttemp < 85 And t.currenttemp > 45 Then

                lblFeelsLike.Text = ""
                tbFeelsLike.Text = ""

            End If

            If t.currenttemp > 85 Then

                lblFeelsLike.Text = "Heat Index:"

                Dim Temp = t.currenttemp
                Dim RH = CInt(Val(t.humidity))

                tbFeelsLike.Text = (-42.379 + 2.04901523 * Temp) + (10.14333127 * RH) - (0.22475541 * Temp * RH) - (0.00683783 * Temp * Temp) - (0.05481717 * RH * RH) + (0.00122874 * Temp * Temp * RH) + (0.00085282 * Temp * RH * RH) - (0.00000199 * Temp * Temp * RH * RH)

                Dim num As Decimal = CType(tbFeelsLike.Text, Decimal)
                Me.tbFeelsLike.Text = String.Format("{0:n0}", num)
                tbFeelsLike.Text = tbFeelsLike.Text & "°"

            End If

            If t.currenttemp < 45 Then

                lblFeelsLike.Text = "Wind Chill:"
                tbFeelsLike.Text = CInt(Val(t.Chill)) & "°"

            End If


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End If


        Dim day As String = DateTime.Now.ToString("dd")
        If day = tbDate.Text = True Then
            tbDate1.Text = tbDate.Text
            btnWeather.Enabled = True
            lblWorking.Text = ""
        Else
            btnWeather_Click(sender, e)
            tbTries.Text = tbTries.Text + 1
        End If


End Sub
Zack answered 18/11, 2015 at 1:38 Comment(1)
While this might work many times (Requesting until you get updated data), sadly there is no guarantee for it to work always, what if Yahoo keeps sending wrong data for a long while? In manual refresh sometime it takes more than 10-15 attempts to get a data only in correct date (Still not correct time). I can't make my user wait many seconds or even minutes for a manual refresh. Since the problem is from Yahoo's side, I'm going to close this question and wait until they hopefully fix it. I have already reported the problem in their support forums but seems no one checks there or cares ...Guadiana
B
0

I have a workaround: repeatedly call the api until you get a valid result. Here is the code I used to make my own custom weather widget: (when you test the code, it sometimes returns data not available even after 30 tries!)

I also tweeted on #YDN a few days back, but did not get any response.

var ydnwthr={};
var ydnStaleness=100000; //YDN weather api is f'ed up and returns stale data, so hammer it repeatedly and then test for data staleness
var abortydn=30; //abort after these many calls
var delayBetweencalls=200; //in milliseconds
var ydncounter=0;
var ydnInterval;
var apiquery=escape('select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="lansing, mi")');
var ydnapiurl='https://query.yahooapis.com/v1/public/yql?q='+apiquery+'&format=json&env='+escape("store://datatables.org/alltableswithkeys");
$(function() { 
   function markupWeather(){
     if(ydnStaleness>1.5) $("#weather").html('weather data not available..');
     else{ 
       /****************THIS IS WHERE YOU DO WHATEVER YOU WANT WITH THE "GOOD" ydnwthr OBJECT ***********/
      var wthrMarkup = "<div id='swHead'>" + ydnwthr.title.replace(/Conditions for | e[sd]t/ig,"") +  "<sub style='font-size:6pt;color:silver'>" +ydncounter+"</sub>"+"</div>";
  	  wthrMarkup += "<div id='swBody' title='updated:" + ydnwthr.pubDate + ". click for details'><div id='swBodyBg'></div><div id='swCurrent'>";
  	  wthrMarkup += ydnwthr.condition.text + ", " + ydnwthr.condition.temp +"&deg;</div></div>";
  	  $("#weather").html(wthrMarkup);
  	  $("#swBodyBg").css('background-image', 'url(' + /".*"/.exec(ydnwthr.description) + ')');
  	  for (i=0;i<5;i++){ //get 5 day weather and fit to container - (done without jquery for convenience)
  	   var el = document.createElement("div");
  	   el.innerText = ydnwthr.forecast[i].day.substr(0,2) + ": " + ydnwthr.forecast[i].text + ", " + ydnwthr.forecast[i].high + "/"+ ydnwthr.forecast[i].low;
  	   $("#swBody")[0].appendChild(el);
  	   while(parseInt(window.getComputedStyle(el, null).getPropertyValue('height')) > 42) {
  		   var fontSize = parseFloat(window.getComputedStyle(el, null).getPropertyValue('font-size'));
  		   el.style.fontSize = (fontSize - 1) + 'px';
  		 }
  	   }
     }
   }//end markupWeather
   ydnInterval=setInterval(function(){
     if(ydnStaleness<=2 || ydncounter>=abortydn) {
	   clearInterval(ydnInterval);
	   markupWeather();
	 }
     $.ajax({url:ydnapiurl}).done(function(data){
	   ydnwthr = data.query.results.channel.item;
	   if(ydnwthr.pubDate) ydnStaleness=(new Date()-new Date(ydnwthr.pubDate))/3600000;
	 });
	 ydncounter++;
   },delayBetweencalls);
});
#weather {border:3px ridge silver;border-radius:5px;cursor:pointer;width:180px;font:10pt/28px arial,sans-serif}
  #swHead {background:#bddeff;font-weight:bold;text-align:center;border-bottom:1px solid silver}
  #swBodyBg{position:absolute;background-position:center;background-size:100px 100px;background-repeat:no-repeat;opacity: 0.5;height:100%;width:100%;z-index:-1}
  #swBody{margin:0px 3px;position:relative;}
  #swCurrent{padding:5px;font:bold 1.1em arial; width:100%;text-align:center}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="weather" 
  onclick="self.open('http://www.wunderground.com/cgi-bin/findweather/getForecast?brand=wxmap&query=42.74461,-84.47283&lat=42.74461&lon=-84.47283&zoom=11&type=terrain&units=english&rad=0&sat=0&svr=0&cams=0&tor=0&wxsn=1&wxsn.mode=tw&wxsn.opa=50&wxsn.bcdgtemp=0&wxsn.rf=0')">
  <i class="fa fa-spinner fa-spin fa-2x" style="margin:40px 65px"></i>
  <div style="margin:30px">getting weather...</div>
  </div>
Broussard answered 24/11, 2015 at 19:32 Comment(1)
There is a tiny number (subscript, light grey, barely visible) at the end of the header line which shows how many times the api was called before it got the right data. If YDN does not fix this api, the weather.gov is another excellent api which I may switch to. Also NOAA for historical climate data.Broussard

© 2022 - 2024 — McMap. All rights reserved.