jubilee/server/weather.js

43 lines
1020 B
JavaScript
Raw Normal View History

2018-02-23 10:36:49 +00:00
const logger = require('log4js').getLogger('Weather');
const weather = require('openweather-apis');
logger.level = 'debug';
2018-02-23 11:01:20 +00:00
const openWeatherApiKey = process.env.openweatherAPI || '936a0ed9eb23b95cf08fc9f693c24264';
2018-02-23 10:36:49 +00:00
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 };