2016-03-08 21:52:21 +00:00
|
|
|
/**
|
|
|
|
* Created by marti on 14/02/2016.
|
|
|
|
*/
|
2017-03-22 15:48:36 +00:00
|
|
|
const http = require('http');
|
|
|
|
const request = require('request');
|
|
|
|
const Forecast = require('forecast.io');
|
|
|
|
const util = require('util');
|
|
|
|
const jsonfile = require('jsonfile');
|
|
|
|
const fs = require('fs');
|
|
|
|
const logger = require('log4js').getLogger();
|
2016-03-08 21:52:21 +00:00
|
|
|
|
2017-03-22 15:48:36 +00:00
|
|
|
const forecastOptions = {
|
2016-03-08 21:52:21 +00:00
|
|
|
APIKey: '0657dc0d81c037cbc89ca88e383b6bbf',
|
|
|
|
units: 'uk2'
|
|
|
|
};
|
|
|
|
|
2017-03-22 15:48:36 +00:00
|
|
|
const file = __dirname + '/' + 'data.json';
|
|
|
|
|
2016-03-08 21:52:21 +00:00
|
|
|
function saveData(d) {
|
|
|
|
jsonfile.writeFileSync(file, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
doGetWeatherOutlook: function () {
|
2017-03-22 15:48:36 +00:00
|
|
|
logger.info('Retrieving weather..');
|
|
|
|
let j = {};
|
|
|
|
let forecast = new Forecast(forecastOptions);
|
|
|
|
forecast.get(55.8582846, -4.2593033, {units: 'uk2'}, (err, res, data) => {
|
2016-03-08 21:52:21 +00:00
|
|
|
if (err) throw err;
|
2017-03-22 15:48:36 +00:00
|
|
|
logger.debug(util.inspect(data));
|
2016-03-08 21:52:21 +00:00
|
|
|
saveData(data);
|
|
|
|
j.currently = data.currently.summary;
|
|
|
|
j.today = data.daily.data[0].summary;
|
|
|
|
j.later = data.daily.summary;
|
|
|
|
j.alerts = data.alerts || {};
|
|
|
|
});
|
|
|
|
}
|
2016-03-31 16:12:25 +00:00
|
|
|
};
|
2016-03-08 21:52:21 +00:00
|
|
|
|
|
|
|
module.exports.doGetWeatherOutlook();
|