Re-enable PenaTemperatures and improve reliability
This commit is contained in:
parent
3a38d8e589
commit
373c883027
|
@ -4,7 +4,7 @@ var BasePlugin = require('./base.js')
|
|||
const logger = require('../logger')
|
||||
|
||||
class Weather extends BasePlugin {
|
||||
constructor (config) {
|
||||
constructor(config) {
|
||||
super(config)
|
||||
this.name = 'Weather'
|
||||
|
||||
|
@ -31,19 +31,19 @@ class Weather extends BasePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
help () {
|
||||
help() {
|
||||
// | Command | Description
|
||||
return '.saa <kaupunki> Antaa sään maapallon tärkeimmistä sijainneista'
|
||||
}
|
||||
|
||||
test (input) {
|
||||
test(input) {
|
||||
if (input.match(/^\.saa(.*)/i)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
getTemperature (city, code) {
|
||||
getTemperature(city, code) {
|
||||
var language = 'fi'
|
||||
|
||||
var urlArgs = {
|
||||
|
@ -57,7 +57,7 @@ class Weather extends BasePlugin {
|
|||
return promise
|
||||
}
|
||||
|
||||
getTemperatures (cities, code) {
|
||||
getTemperatures(cities, code) {
|
||||
logger.info('getting temperatures ', cities, code)
|
||||
if (typeof code === 'undefined') {
|
||||
code = 'fi'
|
||||
|
@ -76,11 +76,13 @@ class Weather extends BasePlugin {
|
|||
'APPID': this.apikey
|
||||
}
|
||||
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
|
||||
}
|
||||
getPenaTemperatures (start, stop, limit) {
|
||||
getPenaTemperatures(start, stop, limit) {
|
||||
logger.info('getting pena', start, stop, limit)
|
||||
var urlArgs = {}
|
||||
|
||||
|
@ -96,41 +98,47 @@ class Weather extends BasePlugin {
|
|||
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
|
||||
}
|
||||
getTemperatureString (owmCityIds) {
|
||||
getTemperatureString(owmCityIds) {
|
||||
let that = this
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
Promise.all([
|
||||
that.getTemperatures(owmCityIds),
|
||||
// that.getPenaTemperatures()
|
||||
that.getPenaTemperatures()
|
||||
]).then(function (results) {
|
||||
var resultString = ''
|
||||
// OWM
|
||||
results[0].list.forEach(function (data) {
|
||||
let weatherData = []
|
||||
if (results[0] !== undefined) {
|
||||
results[0].list.forEach((data) => {
|
||||
var city = data.name
|
||||
var temp = (data.main.temp - 273.15).toFixed(1)
|
||||
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)
|
||||
resultString += 'Aura (' + temp + ' °C)'
|
||||
}*/
|
||||
|
||||
weatherData.push('Aura (' + temp + ' °C)')
|
||||
}
|
||||
}
|
||||
resultString = weatherData.join(', ')
|
||||
resolve(resultString)
|
||||
}, (str) => reject(str))
|
||||
})
|
||||
return promise
|
||||
}
|
||||
|
||||
result (input) {
|
||||
result(input) {
|
||||
// Different cases
|
||||
let that = this
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user