[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Trying to get the weather from yahooapis

Posted on 2014-07-23
4
Medium Priority
?
540 Views
Last Modified: 2014-07-25
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

0
Comment
Question by:itnifl
  • 2
  • 2
4 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40215520
0
 
LVL 2

Author Comment

by:itnifl
ID: 40216175
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?
0
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 40216191
Try a different api.  I get very frustrated every time I try and use yahoo stuff.  

http://openweathermap.org/city/3159016
https://developer.forecast.io/
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 40218799
Thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question