mockturtl / cinnamon-weather

DEPRECATED. Use linuxmint/cinnamon-spices-applets instead.
https://cinnamon-spices.linuxmint.com/applets/view/17
28 stars 35 forks source link

5-Day forecast only displays the first two days #36

Closed Angsereg closed 11 years ago

Angsereg commented 11 years ago

Looks like Yahoo changed their api a bit a while back. After some research, and trial and error, I found the solution, and it's pretty simple. With Yahoo's current API, you have to specify the number of days in the weather report, the default is two - today and tomorrow.

I actually made two corrections. The first was to stop an error from hitting my .xsession-errors (something about 'e' not being defined), the second actually corrects the issue at hand. If you replace the '%26' with an actual ampersand, it doesn't work.

The unified diff follows:

--- applet-original.js  2013-06-04 23:23:53.689891178 -0600
+++ applet.js   2013-06-04 23:07:01.078225323 -0600
@@ -574,7 +574,7 @@
                    forecastUi.Icon.icon_name = this.get_weather_icon_safely(code);
                }
            } catch(error) {
-               logError(e);
+               logError(error);
            }
        });

@@ -827,7 +827,7 @@
     */
    get_weather_url: function() {
        //return QUERY_URL + ' where location="' + this._woeid + '" and u="' + this.unit_to_url() + '"';
-       return QUERY_URL + this._woeid + '_' + this.unit_to_url() + '.xml"' ;
+       return QUERY_URL + this._woeid + '%26d_' + this.unit_to_url() + '.xml"' ;
    },

    /**
mockturtl commented 11 years ago

logError(error);

Thanks for catching that. It will ship in the next release.

As for url-encoding the ampersand, I don't think it's necessary for 5-day results. The apparent failure seems to be a snag with Cinnamon 1.8's "upgrade." See if the cinnamon.next branch works for you. I'll release it soon.

Angsereg commented 11 years ago

No problem for the catch, typos are easy to overlook - my diff is missing the complete "&d=5" in the url - the suggestion for working with the newer Yahoo api is to specify the number of days, so that you aren't subject to whatever the current default is (might be two days, might be 7).

As for the url-encoding, it was the only way I could find that correctly included the "&d=5" in the query, and still worked in both the official 1.8 from Maya's repo, and 1.9 from Gwnedal LE BIHAN's nightly PPA. I wanted to make sure it would work for those using the official repos. Without that "&d=5", I was only getting the first 2 of the 5 day forecast, like many over at http://cinnamon-spices.linuxmint.com/applets/view/17.

mockturtl commented 11 years ago

the suggestion for working with the newer Yahoo api is to specify the number of days, so that you aren't subject to whatever the current default is (might be two days, might be 7).

Can you provide a link? I didn't write most of this code, so I'm not too familiar with the api.

Without that "&d=5", I was only getting the first 2 of the 5 day forecast

See if it's fixed in 1.8.0 (just released). Things look good on my end without the d param; I figure something broke in the Cinnamon 1.8 upgrade. I'm hoping I won't need a script to clean up the old mechanism (gsettings).

Angsereg commented 11 years ago

There were a bunch of us having this issue, and I decided that the timing was too far back to have been the Cinnamon update, one of my machines is on Gwen's nightly builds and had been on 1.8 for quite a while before the 5-day became a 2-day forecast. We weren't the only ones, as my research revealed: http://developer.yahoo.com/forum/General-Discussion-at-YDN/Yahoo-Weather-5-day-Forecast/1228762478000-84d25277-b9c6-35c0-8c54-c487a5093090

If you look at Jack's response, almost to the bottom of that page, he discovered the "${location}&d=${days}.xml" fix, which not only wasn't documented at the time, but I'm not sure if it's been documented YET. Somewhere in that same page, is the url to play with/test api calls like these, possibly an earlier response in that same thread. That's how I was able to verify the fix. I won't be able to research the actual documentation until I get home later tonight (probably about 6 more hours), and if I find anything in the documentation about this, I'll make sure to post it here.

And, since I noticed I hadn't really thanked you for this VERY functional applet: Thank you, thank you, THANK YOU VERY MUCH FOR THIS VERY USEFUL APPLET! :smile:

mockturtl commented 11 years ago

Ah, Yahoo's service was broken. (more reports)

Thanks for following up. Please do report anything you find documenting the request params.