mirror of
https://gitlab.silvrtree.co.uk/martind2000/old-silvrgit.git
synced 2025-01-10 22:05:07 +00:00
updated today.js
This commit is contained in:
parent
609f028a47
commit
6805b955c5
@ -1,12 +1,11 @@
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
title= Today
|
||||
|
||||
title
|
||||
Today
|
||||
body
|
||||
h1 Today
|
||||
.stuff
|
||||
!{data.today}
|
||||
.stuff !{data.today}
|
||||
.weather
|
||||
h2 Weather
|
||||
p Currently:
|
||||
|
58
lib/today.js
58
lib/today.js
@ -3,7 +3,7 @@
|
||||
*/
|
||||
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 jsonfile = require('jsonfile'), fs = require('fs');
|
||||
var log4js = require('log4js');
|
||||
var logger = log4js.getLogger();
|
||||
|
||||
@ -13,7 +13,7 @@ var todayCache = {
|
||||
trains: {last: 0, data: []},
|
||||
weather: {},
|
||||
history: [],
|
||||
today : ''
|
||||
today: ''
|
||||
},
|
||||
expire: ((60 * 1000) * 60)
|
||||
};
|
||||
@ -40,20 +40,24 @@ var mailer = new UltraSES({
|
||||
}
|
||||
});
|
||||
|
||||
var file = 'data.json';
|
||||
var htmlfile = '../today.html';
|
||||
var file = __dirname + '/' + 'data.json';
|
||||
var htmlfile = __dirname + '/' + 'today.html';
|
||||
|
||||
function saveData() {
|
||||
jsonfile.writeFileSync(file, todayCache);
|
||||
}
|
||||
|
||||
function nth(d) {
|
||||
if(d>3 && d<21) return 'th'; // thanks kennebec
|
||||
if (d > 3 && d < 21) return 'th'; // thanks kennebec
|
||||
switch (d % 10) {
|
||||
case 1: return "st";
|
||||
case 2: return "nd";
|
||||
case 3: return "rd";
|
||||
default: return "th";
|
||||
case 1:
|
||||
return "st";
|
||||
case 2:
|
||||
return "nd";
|
||||
case 3:
|
||||
return "rd";
|
||||
default:
|
||||
return "th";
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,17 +72,15 @@ function dayNumber() {
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
function DayDiff(CurrentDate)
|
||||
{
|
||||
var TYear=CurrentDate.getFullYear();
|
||||
var TDay=new Date("January, 01, " + (parseInt(TYear)+1));
|
||||
function DayDiff(CurrentDate) {
|
||||
var TYear = CurrentDate.getFullYear();
|
||||
var TDay = new Date("January, 01, " + (parseInt(TYear) + 1));
|
||||
TDay.getFullYear(TYear);
|
||||
var DayCount=(TDay-CurrentDate)/(1000*60*60*24);
|
||||
DayCount=Math.round(DayCount);
|
||||
return(DayCount);
|
||||
var DayCount = (TDay - CurrentDate) / (1000 * 60 * 60 * 24);
|
||||
DayCount = Math.round(DayCount);
|
||||
return (DayCount);
|
||||
}
|
||||
|
||||
|
||||
Array.prototype.indexOfOld = Array.prototype.indexOf;
|
||||
|
||||
Array.prototype.indexOf = function (e, fn) {
|
||||
@ -100,7 +102,7 @@ module.exports = {
|
||||
getToday: function (req, res) {
|
||||
res.render('pages/today', todayCache);
|
||||
},
|
||||
getTodayDate: function() {
|
||||
getTodayDate: function () {
|
||||
var s, d = new Date();
|
||||
todayCache.data.history = [];
|
||||
|
||||
@ -133,7 +135,7 @@ module.exports = {
|
||||
|
||||
tdihbody.find('.tdihevent > p').each(function (div) {
|
||||
|
||||
// logger.info($(this));
|
||||
// logger.info($(this));
|
||||
var s = $(this).text();
|
||||
if (s.indexOf('Today\'s recipe:') == -1) {
|
||||
output.push(s);
|
||||
@ -155,8 +157,6 @@ module.exports = {
|
||||
|
||||
url = ['http://www.bbc.co.uk/scotland/history/onthisday/', month, '/', day].join('');
|
||||
|
||||
|
||||
|
||||
console.log(url);
|
||||
request(url, function (err, resp, body) {
|
||||
if (err)
|
||||
@ -293,17 +293,20 @@ function sendEmail() {
|
||||
subject: 'Today - ' + dateFormat(now, "dddd, mmmm dS, yyyy")
|
||||
};
|
||||
|
||||
var template = {file: 'jade/today.jade', locals: todayCache};
|
||||
var template = {file: __dirname + '/' + 'jade/today.jade', locals: todayCache};
|
||||
|
||||
logger.debug(__dirname);
|
||||
logger.debug(__dirname.substr(__dirname.lastIndexOf('/'), __dirname.length));
|
||||
|
||||
//if (__dirname.substr(__dirname.lastIndexOf('/'),__dirname.length))
|
||||
mailer.sendTemplate(email, template, function (err) {
|
||||
if (err) throw err;
|
||||
console.log('compiled template email sent');
|
||||
});
|
||||
|
||||
/* console.log(JSON.stringify(todayCache));*/
|
||||
var fn = jade.compileFile(template.file);
|
||||
|
||||
var fn = jade.compileFile(template.file);
|
||||
|
||||
console.log(fn(todayCache));
|
||||
console.log(fn(todayCache));
|
||||
|
||||
fs.writeFileSync(htmlfile, fn(todayCache));
|
||||
|
||||
@ -318,8 +321,7 @@ setTimeout(function () {
|
||||
setTimeout(function () {
|
||||
// console.log('Pre loading trains...');
|
||||
module.exports.getTodayDate();
|
||||
module.exports.getHistory();
|
||||
|
||||
module.exports.getHistory();
|
||||
|
||||
}, 25000);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user