Merge branch 'json'

yahoo_weather
simon04 13 years ago
commit 5aadd4ec56
  1. 41
      src/extension.js

@ -205,11 +205,7 @@ WeatherMenuButton.prototype = {
},
get_weather_url: function() {
return 'http://weather.yahooapis.com/forecastjson?u=' + this.unit_to_url() + '&p=' + this._woeid;
},
get_forecast_url: function() {
return 'http://query.yahooapis.com/v1/public/yql?format=json&q=select%20item.forecast%20from%20weather.forecast%20where%20location%3D%22' + this._woeid + '%22%20%20and%20u="' + this.unit_to_url() + '"';
return 'http://query.yahooapis.com/v1/public/yql?format=json&q=select location,wind,atmosphere,units,item.condition,item.forecast from weather.forecast where location="' + this._woeid + '" and u="' + this.unit_to_url() + '"';
},
get_weather_icon: function(code) {
@ -462,9 +458,13 @@ WeatherMenuButton.prototype = {
},
refreshWeather: function(recurse) {
// Refresh current weather
this.load_json_async(this.get_weather_url(), function(weather) {
this.load_json_async(this.get_weather_url(), function(json) {
let weather = json.get_object_member('query').get_object_member('results').get_object_member('channel');
let weather_c = weather.get_object_member('item').get_object_member('condition');
let forecast = weather.get_object_member('item').get_array_member('forecast').get_elements();
/* TODO won't work with the new URL
// Fixes wrong woeid if necessary
try {
// Wrong woeid specified
@ -485,33 +485,33 @@ WeatherMenuButton.prototype = {
} catch(e) {
global.log('A ' + e.name + ' has occured: ' + e.message);
}
*/
let location = weather.get_object_member('location').get_string_member('city');
if (this._city != null && this._city.length > 0)
location = this._city;
let comment = weather.get_object_member('condition').get_string_member('text');
// Refresh current weather
let comment = weather_c.get_string_member('text');
if (this._translate_condition)
comment = this.get_weather_condition(weather.get_object_member('condition').get_string_member('code'));
comment = this.get_weather_condition(weather_c.get_string_member('code'));
let temperature = weather.get_object_member('condition').get_double_member('temperature');
let temperature = weather_c.get_string_member('temp');
let humidity = weather.get_object_member('atmosphere').get_string_member('humidity') + ' %';
let pressure = weather.get_object_member('atmosphere').get_double_member('pressure');
let pressure = weather.get_object_member('atmosphere').get_string_member('pressure');
let pressure_unit = weather.get_object_member('units').get_string_member('pressure');
let wind_direction = weather.get_object_member('wind').get_string_member('direction');
let wind = weather.get_object_member('wind').get_double_member('speed');
let wind = weather.get_object_member('wind').get_string_member('speed');
let wind_unit = weather.get_object_member('units').get_string_member('speed');
let iconname = this.get_weather_icon_safely(weather.get_object_member('condition').get_string_member('code'));
let iconname = this.get_weather_icon_safely(weather_c.get_string_member('code'));
this._currentWeatherIcon.icon_name = this._weatherIcon.icon_name = iconname;
if(this._comment_in_panel)
if (this._comment_in_panel)
this._weatherInfo.text = (comment + ' ' + temperature + ' ' + this.unit_to_unicode());
else
this._weatherInfo.text = (temperature + ' ' + this.unit_to_unicode());
this._currentWeatherSummary.text = comment;
this._currentWeatherLocation.text = location;
this._currentWeatherTemperature.text = temperature + ' ' + this.unit_to_unicode();
@ -519,16 +519,11 @@ WeatherMenuButton.prototype = {
this._currentWeatherPressure.text = pressure + ' ' + pressure_unit;
this._currentWeatherWind.text = (wind_direction ? wind_direction + ' ' : '') + wind + ' ' + wind_unit;
});
// Refresh forecast
this.load_json_async(this.get_forecast_url(), function(forecast) {
// Refresh forecast
let date_string = [_('Today'), _('Tomorrow')];
forecast = forecast.get_object_member('query').get_object_member('results').get_array_member('channel').get_elements();
for (let i = 0; i <= 1; i++) {
let forecastUi = this._forecast[i];
let forecastData = forecast[i].get_object().get_object_member('item').get_object_member('forecast');
let forecastData = forecast[i].get_object();
let code = forecastData.get_string_member('code');
let t_low = forecastData.get_string_member('low');

Loading…
Cancel
Save