/** * Created by marti on 14/02/2016. */ var http = require('http'), request = require('request'), cheerio = require('cheerio'), Forecast = require('forecast.io'), util = require('util'), UltraSES = require('ultrases'), cron = require('node-cron'); var jade = require('jade'), _ = require('lodash'), dateFormat = require('dateformat'); var jsonfile = require('jsonfile'), fs = require('fs'); var log4js = require('log4js'); var logger = log4js.getLogger(); var forecastOptions = { APIKey: '0657dc0d81c037cbc89ca88e383b6bbf', units: 'uk2' }; var file = __dirname + '/' + 'data.json'; function saveData(d) { jsonfile.writeFileSync(file, d); } module.exports = { doGetWeatherOutlook: function () { console.log('Retrieving weather..'); var j = {}; var forecast = new Forecast(forecastOptions); forecast.get(55.8582846, -4.2593033, {units: 'uk2'}, function (err, res, data) { if (err) throw err; console.log(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 || {}; // todayCache.data.weather = j; }); } }; module.exports.doGetWeatherOutlook();