Community

You need to log in to create posts and topics.

weather data

I was able to set the time zone. But the weather data is still "wrong" how can i set it up?

If you are comfortable editing text files you can change it in /usr/bin/js/yahooWeather.js

For those who want the display to show fahrenheit instead of celsius, edit "/usr/bin/js/weather.js"

Replace the lines:

 // TODO: implement fahrenheit handling
     cardObj.elements.push(generateImageElement(
                              elementId.weatherUnitIndicator, 
                              generateImgPath(imgRootPath, weatherImg['celsius']), 
                              194, 22)
                           );

With:

cardObj.elements.push(generateTextElement(
                         elementId.weatherUnitIndicator,
                         '\u00B0F',
                         30,
                         194, 22, 'right')
                     );

Note: There doesn't appear to be a pre-generated fahrenheit image. Not sure why they needed to use images in the first place, as the text version is pretty much indistinguishable from the image version.

 

I just changed 'celsius' to 'fahrenheit' and it seemed to work in that code sample.

Interesting -- I got a placeholder "NO SUCH IMAGE" when I tried that.

 

I was just blindly copying it from the declaration around line 24

Hi all

Hi, in trying to change my yahooweather. js to Celsius and metric, I broke my code. Can someone please tell me the original code? Unfortunately, I deleted the file with the backup. Thanks!

var yahooConditionCodes = [

        'windy', //0    tornado

        'windy', //1    tropical storm

        'windy', //2    hurricane

        'rain', //3     severe thunderstorms

        'rain', //4     thunderstorms

        'rain', //5     mixed rain and snow

        'rain', //6     mixed rain and sleet

        'snow', //7     mixed snow and sleet

        'rain', //8     freezing drizzle

        'rain', //9     drizzle

        'rain', //10    freezing rain

        'rain', //11    showers

        'rain', //12    showers

        'snow', //13    snow flurries

        'snow', //14    light snow showers

        'snow', //15    blowing snow

        'snow', //16    snow

        'snow', //17    hail

        'snow', //18    sleet

        'windy', //19   dust

        'rain', //20    foggy

        'rain', //21    haze

        'rain', //22    smoky

        'windy', //23   blustery

        'windy', //24   windy

        'windy', //25   cold

        'cloudy', //26  cloudy

        'nightCloudy', //27     mostly cloudy (night)

        'partlyCloudy', //28    mostly cloudy (day)

        'nightCloudy', //29     partly cloudy (night)

        'partlyCloudy', //30    partly cloudy (day)

        'sunny', //31   clear (night)

        'sunny', //32   sunny

        'sunny', //33   fair (night)

        'sunny', //34   fair (day)

        'rainy', //35   mixed rain and hail

        'sunny', //36   hot

        'rain', //37    isolated thunderstorms

        'rain', //38    scattered thunderstorms

        'rain', //39    scattered thunderstorms

        'rain', //40    scattered showers

        'snow', //41    heavy snow

        'snow', //42    scattered snow showers

        'snow', //43    heavy snow

        'partlyCloudy', //44    partly cloudy

        'rain', //45    thundershowers

        'snow', //46    snow showers

        'rain' //47     isolated thundershowers

];

function buildUrl (location, tempUnit) {

        var tempUnitIndicator = 'c';

        if (tempUnit === 'fahrenheit' || tempUnit === 'imperial')       tempUnitIndicator = 'f';

        var query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + location + '") and u=\'' + tempUnitIndicator + '\'';

        var url = 'https://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json'

        return url;

}

function getYahooWeather (location, tempUnit, distanceUnit) {

    print('getting yahoo weather');

    var result = httpRequest({

        method: 'GET',

        url: buildUrl(location, tempUnit)

    });

    // result = result.replace(/0\s*$/g, '')

    // result = result.replace(/\n/g, '')

        if (result) {

            var jsonResult;

            try {

                jsonResult = JSON.parse(result);

            } catch(e) {

                print(e); // error in the above string!

                                        print(result);

                return null;

            }

            // special case where there is a mismatch between temperature and distance units

            if (tempUnit === 'fahrenheit' && distanceUnit === 'metric') {

                // convert imperial wind speed to metric

                jsonResult.query.results.channel.wind.speed = parseFloat(jsonResult.query.results.channel.wind.speed) * 1.60934;

            }

            var weatherObj = {

                'temperature': jsonResult.query.results.channel.item.condition.temp,

                'condition': yahooConditionCodes[parseInt(jsonResult.query.results.channel.item.condition.code)],

                'wind': parseInt(jsonResult.query.results.channel.wind.speed)

            }

            return weatherObj;

        }

        else {

                return null;

        }

}

~

~

~

~

~

~

~

~

~

~

~

~

~

- /usr/bin/js/yahooWeather.js 25/100 25%