Question

I'm trying to get the hourly forecast temperature for a specific hour of the day from the Wunderground API for a research project:

This is an example of the JSON: http://api.wunderground.com/api/[key]/geolookup/astronomy/forecast/history_/hourly/conditions/q/mo/columbia.json

The specific section looks like this:

"hourly_forecast": [
    {
    "FCTTIME": {
    "hour": "17","hour_padded": "17","min": "00","sec": "0","year": "2013","mon": "7","mon_padded": "07","mon_abbrev": "Jul","mday": "15","mday_padded": "15","yday": "195","isdst": "1","epoch": "1373925600","pretty": "5:00 PM CDT on July 15, 2013","civil": "5:00 PM","month_name": "July","month_name_abbrev": "Jul","weekday_name": "Monday","weekday_name_night": "Monday Night","weekday_name_abbrev": "Mon","weekday_name_unlang": "Monday","weekday_name_night_unlang": "Monday Night","ampm": "PM","tz": "","age": ""
    },
    "temp": {"english": "86", "metric": "30"},
    "dewpoint": {"english": "71", "metric": "22"},
    "condition": "Thunderstorm",
    "icon": "tstorms",
    "icon_url":"http://icons-ak.wxug.com/i/c/k/tstorms.gif",
    "fctcode": "15",
    "sky": "66",
    "wspd": {"english": "10", "metric": "16"},
    "wdir": {"dir": "ESE", "degrees": "119"},
    "wx": "Scattered Thunderstorms , Scattered Light Rain Showers",
    "uvi": "3",
    "humidity": "60",
    "windchill": {"english": "-9998", "metric": "-9998"},
    "heatindex": {"english": "91", "metric": "33"},
    "feelslike": {"english": "91", "metric": "33"},
    "qpf": {"english": "", "metric": ""},
    "snow": {"english": "", "metric": ""},
    "pop": "30",
    "mslp": {"english": "30.14", "metric": "1020"}
    }
    ,

I get the JSON like so:

$.ajax({
    url : "http://api.wunderground.com/api/[key]/geolookup/forecast/hourly/history_/astronomy/conditions/q/"+lat+","+lon+".json",
    dataType : "jsonp",
    success : function(parsed_json) {

Then I try to run through the hourly forecasts like so (normally mday and hour are replaced with a variable containing today's date and a specific hour, but for troubleshooting, I put these numbers in).

// get the forecast 
    $.each( parsed_json['hourly_forecast'], function( i, value )    {
        if( value.FCTTIME.mday  == 15 && value.FCTTIME.hour == 19) {
            six_hour_forecast = value.temp.english;
        }

However, I consistently get the wrong temp.english for six_hour_forecast.

So close — what am I missing?

Was it helpful?

Solution

This did it:

// Get the forecast 6 hour temp
$.each( parsed_json['hourly_forecast'], function( index, value )    {
    if( value['FCTTIME']['hour']==sunrise_hour*1 + 6 && value['FCTTIME']['mday']==window.current_day ) {
    window.six_hour_forecast = value.temp.english;
    }
}); // end each
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top