From e2463d19bcac8c29585ad865e26fec3cb6d5cfce Mon Sep 17 00:00:00 2001 From: martind2000 Date: Sun, 14 Feb 2016 23:00:15 +0000 Subject: [PATCH] updated weather --- lib/jade/today.jade | 4 +++- lib/today.js | 3 ++- lib/weather.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 lib/weather.js diff --git a/lib/jade/today.jade b/lib/jade/today.jade index 399a4bf..c93f98d 100644 --- a/lib/jade/today.jade +++ b/lib/jade/today.jade @@ -11,8 +11,10 @@ html(lang="en") h2 Weather p Currently: = ' ' + data.weather.currently - p Later: + p Today: = ' ' + data.weather.today + p Later: + = ' ' + data.weather.later if data.weather.alerts.length > 0 h3 ALERT diff --git a/lib/today.js b/lib/today.js index 345c8ab..d091867 100644 --- a/lib/today.js +++ b/lib/today.js @@ -251,7 +251,8 @@ module.exports = { if (err) throw err; j.currently = data.currently.summary; - j.today = data.daily.summary; + j.today = data.daily[0].summary; + j.later = data.daily.summary; j.alerts = data.alerts || {}; todayCache.data.weather = j; diff --git a/lib/weather.js b/lib/weather.js new file mode 100644 index 0000000..4bc6f4c --- /dev/null +++ b/lib/weather.js @@ -0,0 +1,44 @@ +/** + * 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[0].summary; + j.later = data.daily.summary; + j.alerts = data.alerts || {}; + + // todayCache.data.weather = j; + }); + + } +} +; + + +module.exports.doGetWeatherOutlook(); \ No newline at end of file