/** * Created by marti on 14/02/2016. */ 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(); const forecastOptions = { APIKey: '0657dc0d81c037cbc89ca88e383b6bbf', units: 'uk2' }; const file = __dirname + '/' + 'data.json'; function saveData(d) { jsonfile.writeFileSync(file, d); } module.exports = { doGetWeatherOutlook: function () { logger.info('Retrieving weather..'); let j = {}; let forecast = new Forecast(forecastOptions); forecast.get(55.8582846, -4.2593033, {units: 'uk2'}, (err, res, data) => { if (err) throw err; logger.debug(util.inspect(data)); saveData(data); j.currently = data.currently.summary; j.today = data.daily.data[0].summary; j.later = data.daily.summary; j.alerts = data.alerts || {}; }); } }; module.exports.doGetWeatherOutlook();