var penaapi = require('./../penaapi')(); var Promise = require('promise'); var iconCodeToText = { '01d': 'selkeää', '02d': 'puolipilvistä', '03d': 'pilvistä', '04d': 'pilvipeite rakoilee', '09d': 'sadekuuroja', '10d': 'vesisadetta', '11d': 'ukkostaa', '13d': 'lumisadetta', '50d': 'sumua', '01n': 'selkeää', '02n': 'puolipilvistä', '03n': 'pilvistä', '04n': 'pilvipeite rakoilee', '09n': 'sadekuuroja', '10n': 'vesisadetta', '11n': 'ukkostaa', '13n': 'lumisadetta', '50n': 'sumua' }; module.exports = function(config) { var owmapi = require('./../owmapi')(config); var getTemperatureString = function(owmCityIds) { var promise = new Promise(function(resolve, reject) { Promise.all([ owmapi.getTemperatures(owmCityIds), penaapi.getTemperatures() ]).then(function(results) { var resultString = ''; // OWM results[0].list.forEach(function(data) { var city = data.name; var temp = (data.main.temp-273.15).toFixed(1); var code = data.weather[0].icon; resultString += '' + city + ' ('+temp+' °C, '+iconCodeToText[code]+'), '; }); if(results[1].length > 0) { var temp = Number(results[1][0].temp).toFixed(1); resultString += 'Aura (' + temp + ' °C)'; } resolve(resultString); }); }); return promise; }; return getTemperatureString; };