updated weather

This commit is contained in:
martind2000 2016-02-14 23:00:15 +00:00
parent 3723b544ce
commit e2463d19bc
3 changed files with 49 additions and 2 deletions

View File

@ -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

View File

@ -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;

44
lib/weather.js Normal file
View File

@ -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();