43 lines
988 B
JavaScript
43 lines
988 B
JavaScript
|
|
const logger = require('log4js').getLogger('Weather');
|
|
const weather = require('openweather-apis');
|
|
|
|
logger.level = 'debug';
|
|
|
|
const openWeatherApiKey = process.env.openweatherAPI || '';
|
|
|
|
weather.setAPPID(openWeatherApiKey);
|
|
weather.setLang('en');
|
|
// weather.setCity('Glasgow City');
|
|
|
|
function doGetOpenWeather(ll) {
|
|
const [lat, long ] = ll.split(',');
|
|
|
|
return new Promise((resolve, reject) => {
|
|
weather.setCoordinate(lat, long);
|
|
weather.getWeatherForecast( function(err, wData) {
|
|
if (err)
|
|
return reject(err);
|
|
else
|
|
return resolve(wData);
|
|
});
|
|
});
|
|
}
|
|
|
|
function doGetOpenWeatherForecast(ll) {
|
|
const [lat, long ] = ll.split(',');
|
|
|
|
return new Promise((resolve, reject) => {
|
|
weather.setCoordinate(lat, long);
|
|
weather.getWeatherForecastForDays(5, function(err, wData) {
|
|
if (err)
|
|
return reject(err);
|
|
else
|
|
return resolve(wData);
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
module.exports = { doGetOpenWeather, doGetOpenWeatherForecast };
|