Re-enable PenaTemperatures and improve reliability

This commit is contained in:
lanxu 2022-05-07 15:29:37 +03:00
parent 3a38d8e589
commit 373c883027

View File

@ -76,7 +76,9 @@ class Weather extends BasePlugin {
'APPID': this.apikey 'APPID': this.apikey
} }
var url = 'http://api.openweathermap.org/data/2.5/group' var url = 'http://api.openweathermap.org/data/2.5/group'
var promise = requestPromise(url, urlArgs) var promise = requestPromise(url, urlArgs).catch(e => {
logger.error('Failed to retrieve openweathermap data')
})
return promise return promise
} }
@ -96,9 +98,11 @@ class Weather extends BasePlugin {
urlArgs.stop = stop urlArgs.stop = stop
} }
var url = 'http://masa.dy.fi/api/temperature.php' var url = 'https://masa.dy.fi/api/temperature.php'
var promise = requestPromise(url, urlArgs) var promise = requestPromise(url, urlArgs).catch(e => {
logger.error('Failed to retrieve pena temperatures data')
})
return promise return promise
} }
@ -107,23 +111,27 @@ class Weather extends BasePlugin {
var promise = new Promise(function (resolve, reject) { var promise = new Promise(function (resolve, reject) {
Promise.all([ Promise.all([
that.getTemperatures(owmCityIds), that.getTemperatures(owmCityIds),
// that.getPenaTemperatures() that.getPenaTemperatures()
]).then(function (results) { ]).then(function (results) {
var resultString = '' var resultString = ''
// OWM // OWM
results[0].list.forEach(function (data) { let weatherData = []
if (results[0] !== undefined) {
results[0].list.forEach((data) => {
var city = data.name var city = data.name
var temp = (data.main.temp - 273.15).toFixed(1) var temp = (data.main.temp - 273.15).toFixed(1)
var code = data.weather[0].icon var code = data.weather[0].icon
resultString += '' + city + ' (' + temp + ' °C, ' + that.iconCodeToText[code] + '), ' weatherData.push(city + ' (' + temp + ' °C, ' + that.iconCodeToText[code] + ')')
}) })
}
/*if (results[1].length > 0) { if (results[1] !== undefined) {
if (results[1].length > 0) {
var temp = Number(results[1][0].temp).toFixed(1) var temp = Number(results[1][0].temp).toFixed(1)
resultString += 'Aura (' + temp + ' °C)' weatherData.push('Aura (' + temp + ' °C)')
}*/ }
}
resultString = weatherData.join(', ')
resolve(resultString) resolve(resultString)
}, (str) => reject(str)) }, (str) => reject(str))
}) })