Use id instead of location name to fetch weatherdata. Fix for a bug with cities (locations) with the same name in different countries.

multiprovider
Jens Lody 11 years ago
parent b60a00c174
commit 1aadd7c489
  1. 11
      src/extension.js
  2. 17
      src/prefs.js

@ -368,7 +368,7 @@ const WeatherMenuButton = new Lang.Class({
},
locationChanged: function() {
let location = this.extractCity(this._city);
let location = this.extractId(this._city);
if (this.oldLocation != location) {
return true;
}
@ -724,7 +724,6 @@ const WeatherMenuButton = new Lang.Class({
}
for (let a in cities) {
if (!this.extractCity(cities[a])) {
let params = {
q: cities[a],
@ -1406,10 +1405,10 @@ weather-storm.png = weather-storm-symbolic.svg
this.updateCities();
return;
}
this.oldLocation = this.extractCity(this._city);
this.oldLocation = this.extractId(this._city);
let params = {
q: this.oldLocation,
id: this.oldLocation,
units: 'metric'
};
if (this._appid)
@ -1540,10 +1539,10 @@ weather-storm.png = weather-storm-symbolic.svg
return;
}
this.oldLocation = this.extractCity(this._city);
this.oldLocation = this.extractId(this._city);
let params = {
q: this.oldLocation,
id: this.oldLocation,
units: 'metric',
cnt: '13'
};

@ -375,8 +375,8 @@ const WeatherPrefsWidget = new GObject.Class({
units: 'metric',
q: location
};
if (this._appid)
params['APPID'] = this._appid;
if (this.appid)
params['APPID'] = this.appid;
if (testLocation(location) == 0)
this.loadJsonAsync(WEATHER_URL_FIND, params, function() {
if (!arguments[0])
@ -433,16 +433,16 @@ const WeatherPrefsWidget = new GObject.Class({
if (entry.get_text().search(/\[/) == -1 || entry.get_text().search(/\]/) == -1)
return 0;
let name = entry.get_text().split(/,/)[0];
if (!name)
let id = entry.get_text().split(/\[/)[1].split(/\]/)[0];
if (!id)
return 0;
let params = {
q: name,
id: id,
type: 'accurate'
};
if (this._appid)
params['APPID'] = this._appid;
if (this.appid)
params['APPID'] = this.appid;
this.loadJsonAsync(WEATHER_URL_CURRENT, params, Lang.bind(this, function() {
if (!arguments[0])
return 0;
@ -451,14 +451,13 @@ const WeatherPrefsWidget = new GObject.Class({
if (Number(city.cod) != 200)
return 0;
let id = entry.get_text().split(/\[/)[1].split(/\]/)[0];
if (!id)
return 0;
if (id != city.id)
return 0;
let cityText = city.name;
let cityText = entry.get_text().split(/,/)[0];
if (city.sys)
cityText += " (" + city.sys.country + ")";

Loading…
Cancel
Save