Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

asked on

Trying to get the weather from yahooapis

This should return the weather for my location:

http://query.yahooapis.com/v1/public/yql?q=SELECT%20item.condition%20FROM%20weather.forecast%20WHERE%20location=%27NOXX0008%27%20AND%20u=%27c%27&format=json&_nocache=1001

The temperature is correct, but the code is always 3200, which means 'not available' - see https://developer.yahoo.com/weather/

It wasn't always like that. I used to get the correct code in return. Anyone know if I am doing something wrong or if there is some tweak to this?

The javascript I use is this:
$(function(){
    // Specify the ZIP/location code and units (f or c)
    var loc = 'NOXX0008'; // or e.g. SPXX0050
    var u = 'c';

    var query = "SELECT item.condition FROM weather.forecast WHERE location='" + loc + "' AND u='" + u + "'";
    var cacheBuster = Math.floor((new Date().getTime()) / 1200 / 1000);
    var url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json&_nocache=' + cacheBuster;

    window['wxCallback'] = function(data) {
        var info = data.query.results.channel.item.condition;        
        $('#wxIcon').css({
            backgroundPosition: '-' + (61 * info.code) + 'px 0'
        }).attr({
            title: info.text
        });
        $('#wxIcon2').append('<img src="http://l.yimg.com/a/i/us/we/52/' + info.code + '.gif" width="34" height="34" title="' + info.text + '" />');
        $('#wxTemp').html(info.temp + '&deg;' + (u.toUpperCase()));
    };

    $.ajax({
        url: url,
        dataType: 'jsonp',
        cache: true,
        jsonpCallback: 'wxCallback'
    });
});

Open in new window

Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Avatar of itnifl

ASKER

https://www.edg3.uk/snippets/weather-location-codes/
This tells me NOXX0008 is the code for Drammen, Norway. It is the code that I use.

I could also use woeid like you do. In this case I used 29326649 which I got from http://woeid.rosselliot.co.nz/lookup/drammen. Like the site suggests, the code result is 3200 in this case also:
https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%3D29326649&diagnostics=true

So, Yahoo having problems with measuring the weather at my location? Who should I contact?
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itnifl

ASKER

Thank you