updated calendar to have today, tomorrow and this week

This commit is contained in:
Martin Donnelly 2016-05-03 14:35:43 +01:00
parent 720b61d802
commit 18b382f626
5 changed files with 179 additions and 18 deletions

56
app/test.html Normal file
View File

@ -0,0 +1,56 @@
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>
<Today></Today>
</title>
</head>
<body>
<h1>Today</h1>
<div class="stuff"> <strong>Tuesday May 03, 2016</strong> - The 123rd day of 2016, and there are 242 days left until the end of the year.</div>
<div class="weather">
<h2>Weather</h2>
<p>Currently: Rain. Around 6 to 11 degrees.
</p>
<p>Today: Light rain in the morning.
</p>
<p>Later: Light rain today through Sunday, with temperatures rising to 18°C on Monday.
</p>
</div>
<div class="travel">
<h2>Travel</h2>
<p>Nothing to report.</p>
</div>
<div class="calendar">
<h2>Calendar</h2>
<h3>Today</h3>
<p>Nothing today</p>
<h3>Tomorrow</h3>
<p>Nothing tomorrow</p>
<h3>This week</h3>
<p><em>14:30:00 pm</em> - Kevin / Martin / Michael - Lunch Catch Up, 1 hour</p>
</div>
<div class="fitbit">
</div>
<div class="swedish">
<h2>Word of the day</h2>
<p style="font-weight:900;">otur</p>
<p>It is an expression which means '<em>bad luck</em>'.</p>
<p>Example: Svarta katter betyder otur.</p>
<p>Translated: Black cats are a sign of bad luck.</p>
</div>
<div class="history">
<h2>Today in history</h2>
<p>On this day in 1679, Archbishop James Sharp, Primate of Scotland, was attacked and killed.</p>
<p>The murder happened while he was travelling through Fife to St Andrews. The attackers were probably waiting for the Sheriff of Fife, but were happy to kill instead the man leading the forces suppressing the Covenant in Scotland. It sparked a wider uprising, leading to what is known as the &quot;Killing Time&quot;.</p>
<p>Today in 1860, John Haldane, Scottish physician and physiologist, was born. Noted for his work on respiration, it was Haldane who demonstrated the role of carbon dioxide, and the change in temperature of the human body at extreme pressures. Author of 'Causes of Death in Colliery Explosions,' he was also father of the great population geneticist, JBS Haldane.</p>
<p>Earliest Known Case of Spam</p>
<p>Today, unsolicited bulk email--better known as spam--accounts for up to 90% of all email messages, but it wasn't until this date in 1978 that the first spam was sent. Gary Thuerk, a Digital Equipment Corporation marketer, composed a message promoting the DECSYSTEM-20 computer. The message promoted two upcoming product presentations of the DECSYSTEM-20 accessing the ARPANET. The reaction to the message was swift and highly negative, including one who claimed that the message shut down his system.</p>
</div>
<div class="tv">
<h2>Todays TV</h2>
<p><em>3:00:00 am</em> - Castle 8x20 - Much Ado About Murder, 1 hour</p>
<p><em>3:00:00 am</em> - NCIS: Los Angeles 7x24 - Talion, 1 hour</p>
</div>
</body>
</html>

View File

@ -31,13 +31,30 @@ html(lang="en")
else
p Nothing to report.
.calendar
if data.cal.entries.length > 0
h2 Calendar
each line in data.cal.entries
p !{line.combined}
h2 Calendar
h3 Today
if (data.cal.today.length > 0)
each line in data.cal.today
p !{line.combined}
else
p Nothing today
h3 Tomorrow
if (data.cal.tomorrow.length > 0)
each line in data.cal.tomorrow
p !{line.combined}
else
p Nothing tomorrow
h3 This week
if (data.cal.week.length > 0)
each line in data.cal.week
p !{line.longcombined}
else
p Nothing later this week
.fitbit
h2 Fitbit
p Yesterday you walked #{data.fitbit.summary.steps} steps and covered #{data.fitbit.summary.distances[0].distance} km.
if data.fitbit.summary
h2 Fitbit
p Yesterday you walked #{data.fitbit.summary.steps} steps and covered #{data.fitbit.summary.distances[0].distance} km.
.swedish
h2 Word of the day
p(style="font-weight:900;")= data.swedish.xml.words.word

View File

@ -1 +1 @@
{"last":0,"data":{"trains":{"last":"2016-02-20T00:28:44.255Z","data":[]},"weather":{"currently":"Light Rain. Around 4 to 6 degrees.","today":"Light rain until evening, starting again overnight.","later":"Mixed precipitation throughout the week, with temperatures peaking at 9°C on Monday.","alerts":{}},"history":["King James I was murdered in Perth, by a group led by Sir Robert Graham, today in 1437.","Had it not been for his love of tennis James would have escaped his assassins. Fleeing his killers, he hid in the drain under his tennis court, however this offered no means of escape for the monarch, as he had only recently ordered it to be blocked after losing balls in it.","On 20 February 1472 Orkney and Shetland became part of Scotland. The islands were provided as security for the dowry of Princess Margaret, the prospective wife of James III of Scotland and daughter of King Christian of Norway and Denmark.","Alan Turing Suggests Testing Artificial Intelligence with the Game of Chess","Computer pioneer Alan Turing suggests testing artificial intelligence with the game of chess in a lecture to the London Mathematical Society. Computers, he argued, must like humans be given training before their IQ is tested. A human mathematician has always undergone an extensive training. This training may be regarded as not unlike putting instruction tables into a machine, he said. One must therefore not expect a machine to do a very great deal of building up of instruction tables on its own."],"today":"<strong>February 20</strong> - The 51th day of 2016, and there are 316 days left until the end of the year.","tv":{"entries":[]},"cal":{"entries":[]},"swedish":{"xml":{"$":{"xmlns:wotd":"http://www.transparent.com/word-of-the-day/"},"words":{"date":"02-20-2016","langname":"Swedish","wordtype":"verb","word":"att vänta på","wordsound":"http://wotd.transparent.com/swedish/level-1/sound/00464_WOTD_Swedish_Words.flv","translation":"to wait for","fnphrase":"Vi väntar på bussen.","phrasesound":"http://wotd.transparent.com/swedish/level-1/sound/00464_WOTD_Swedish_Sentences.flv","enphrase":"We are waiting for the bus.","wotd:transliteratedWord":"","wotd:transliteratedSentence":"","notes":""}}}},"expire":3600000}
{"last":0,"data":{"trains":{"last":"2016-05-03T13:34:18.227Z","data":[]},"weather":{},"history":["On this day in 1679, Archbishop James Sharp, Primate of Scotland, was attacked and killed.","The murder happened while he was travelling through Fife to St Andrews. The attackers were probably waiting for the Sheriff of Fife, but were happy to kill instead the man leading the forces suppressing the Covenant in Scotland. It sparked a wider uprising, leading to what is known as the \"Killing Time\".","Today in 1860, John Haldane, Scottish physician and physiologist, was born. Noted for his work on respiration, it was Haldane who demonstrated the role of carbon dioxide, and the change in temperature of the human body at extreme pressures. Author of 'Causes of Death in Colliery Explosions,' he was also father of the great population geneticist, JBS Haldane.","Earliest Known Case of Spam","Today, unsolicited bulk email--better known as spam--accounts for up to 90% of all email messages, but it wasn't until this date in 1978 that the first spam was sent. Gary Thuerk, a Digital Equipment Corporation marketer, composed a message promoting the DECSYSTEM-20 computer. The message promoted two upcoming product presentations of the DECSYSTEM-20 accessing the ARPANET. The reaction to the message was swift and highly negative, including one who claimed that the message shut down his system."],"today":"<strong>Tuesday May 03, 2016</strong> - The 123rd day of 2016, and there are 242 days left until the end of the year.","tv":{"entries":[{"summary":"Castle 8x20 - Much Ado About Murder","dtstart":"2016-05-03T02:00:00.000Z","dtend":"2016-05-03T03:00:00.000Z","description":"After a movie star turned theater actor is mysteriously","timeStart":"3:00:00","timeEnd":"4:00:00","duration":"1 hour","combined":"<em>3:00:00</em> - Castle 8x20 - Much Ado About Murder, 1 hour","long":"<em>Tuesday, 3:00:00</em> - ","longcombined":"<em>Tuesday, 3:00:00</em> - Castle 8x20 - Much Ado About Murder, 1 hour"},{"summary":"NCIS: Los Angeles 7x24 - Talion","dtstart":"2016-05-03T02:00:00.000Z","dtend":"2016-05-03T03:00:00.000Z","description":"When Sam receives a distress code from his son Aiden that his","timeStart":"3:00:00","timeEnd":"4:00:00","duration":"1 hour","combined":"<em>3:00:00</em> - NCIS: Los Angeles 7x24 - Talion, 1 hour","long":"<em>Tuesday, 3:00:00</em> - ","longcombined":"<em>Tuesday, 3:00:00</em> - NCIS: Los Angeles 7x24 - Talion, 1 hour"}]},"cal":{"today":[],"tomorrow":[],"week":[{"summary":"Kevin / Martin / Michael - Lunch Catch Up","dtstart":"2016-05-05T13:30:00.000Z","dtend":"2016-05-05T14:30:00.000Z","description":"Hi Kevin/Martin\\,\\n\\nI do feel our lunch meeting is cursed... I","timeStart":"14:30:00","timeEnd":"15:30:00","duration":"1 hour","combined":"<em>14:30:00</em> - Kevin / Martin / Michael - Lunch Catch Up, 1 hour","long":"<em>Thursday, 14:30:00</em> - ","longcombined":"<em>Thursday, 14:30:00</em> - Kevin / Martin / Michael - Lunch Catch Up, 1 hour"}],"entries":[]},"swedish":{"xml":{"$":{"xmlns:wotd":"http://www.transparent.com/word-of-the-day/"},"words":{"date":"05-03-2016","langname":"Swedish","wordtype":"expression","word":"otur","wordsound":"http://wotd.transparent.com/swedish/level-1/sound/00060_WOTD_Swedish_Words.mp3","translation":"bad luck","fnphrase":"Svarta katter betyder otur.","phrasesound":"http://wotd.transparent.com/swedish/level-1/sound/00060_WOTD_Swedish_Sentences.mp3","enphrase":"Black cats are a sign of bad luck.","wotd:transliteratedWord":"","wotd:transliteratedSentence":"","notes":""}}},"fitbit":{}},"expire":3600000,"date":{"year":2016,"month":5,"day":3}}

View File

@ -21,7 +21,7 @@ require('sugar-date');
var todayCache = {
last: 0, data: {
trains: {last: 0, data: []}, weather: {}, history: [], today: '', tv: {entries: []}, cal: {entries: []}, swedish: {}, fitbit: {}
trains: {last: 0, data: []}, weather: {}, history: [], today: '', tv: {entries: []}, cal: {today: [], tomorrow:[], week:[]}, swedish: {}, fitbit: {}
}, expire: ((60 * 1000) * 60)
};
var file = __dirname + '/' + 'newdata.json';
@ -180,6 +180,7 @@ module.exports = {
'use strict';
console.error(e);
});
calHandler.getSimpleCalV3('http://www.pogdesign.co.uk/cat/download_ics/60cfdff469d0490545d33d7e3b5c0bcc')
.then((d) => {
'use strict';
@ -192,10 +193,12 @@ module.exports = {
for (var t = 0; t < calHandler.calendars.length;t++) {
calHandler.getSimpleCalV3(calHandler.calendars[t])
calHandler.getAdvancedCalV3(calHandler.calendars[t])
.then((d) => {
'use strict';
todayCache.data.cal.entries = todayCache.data.cal.entries.concat(d.entries);
todayCache.data.cal.today = todayCache.data.cal.today.concat(d.today);
todayCache.data.cal.tomorrow = todayCache.data.cal.tomorrow.concat(d.tomorrow);
todayCache.data.cal.week = todayCache.data.cal.week.concat(d.week);
})
.catch((e) => {
'use strict';
@ -274,6 +277,7 @@ setTimeout(function() {
setTimeout(function() {
// MdMailer.sendEmailV1(todayCache, __dirname);
// saveToDB(todayCache);
// saveData();
}, 45000);
cron.schedule('45 6 * * *', function() {
module.exports.preLoadToday();

View File

@ -67,17 +67,20 @@ function processICAL(ical) {
}
if (workBlock.dtstart !== null) {
workBlock.timeStart = workBlock.dtstart.format('{12hr}:{mm}:{ss} {tt}');
workBlock.timeStart = workBlock.dtstart.format('{24hr}:{mm}:{ss}');
workBlock.combined = '<em>' + workBlock.timeStart + '</em> - ';
workBlock.long = '<em>' + workBlock.dtstart.format('{Weekday}') +', ' + workBlock.timeStart + '</em> - ';
}
workBlock.combined = workBlock.combined + workBlock.summary;
workBlock.longcombined = workBlock.long + workBlock.summary;
if (workBlock.dtend !== null) {
workBlock.timeEnd = workBlock.dtend.format('{12hr}:{mm}:{ss} {tt}');
workBlock.timeEnd = workBlock.dtend.format('{24hr}:{mm}:{ss}');
}
if (workBlock.dtstart !== null && workBlock.dtend !== null) {
var elapsedTime = new Elapsed(workBlock.dtstart, workBlock.dtend);
workBlock.duration = elapsedTime.optimal;
workBlock.combined = workBlock.combined + ', ' + elapsedTime.optimal;
workBlock.longcombined = workBlock.longcombined + ', ' + elapsedTime.optimal;
}
return workBlock;
@ -132,10 +135,50 @@ module.exports = {
today.entries.push(this.jsonBlock[t]);
}
}
// Logger.debug(today);
logger.info('- getTodaysSimple');
return today;
},
getTomorrow: function() {
'use strict';
logger.info('+ getTomorrow');
var today = {
entries: []
};
for (var t = 0; t < this.jsonBlock.length; t++) {
if (this.jsonBlock[t].dtstart.isTomorrow()) {
today.entries.push(this.jsonBlock[t]);
}
}
logger.info('- getTomorrow');
return today;
},
getWeek: function() {
'use strict';
logger.info('+ getWeek');
var today = {
entries: []
};
var now, twoDays, sevenDays;
now = Date.create('today');
logger.debug(now);
twoDays = Date.create(now).addDays(2).beginningOfDay();
logger.debug(twoDays);
sevenDays = Date.create(twoDays).addDays(5).beginningOfDay();
logger.debug(now, twoDays, sevenDays);
for (var t = 0; t < this.jsonBlock.length; t++) {
if (this.jsonBlock[t].dtstart.isBetween(twoDays, sevenDays)) {
today.entries.push(this.jsonBlock[t]);
}
}
logger.info('- getWeek');
return today;
},
getTodaysMeetings: function() {
'use strict';
logger.info('+ getTodaysMeetings');
@ -158,7 +201,7 @@ module.exports = {
}
}
}
// Logger.debug(today);
// logger.debug(today);
logger.info('- getTodaysMeetings');
return today;
}, getSimpleCalV2: function(url, cb) {
@ -176,7 +219,7 @@ module.exports = {
self.jsonBlock = processICAL(body);
// Logger.debug(self.jsonBlock);
// logger.debug(self.jsonBlock);
var st = self.getTodaysSimple();
if (typeof cb === 'function') {
@ -200,14 +243,14 @@ module.exports = {
try {
request(url, function(err, res, body) {
if (err) {
// Logger.error(err);
// logger.error(err);
return reject(err);
// Throw err;
}
self.jsonBlock = processICAL(body);
// Logger.debug(self.jsonBlock);
// logger.debug(self.jsonBlock);
var st = self.getTodaysSimple();
return resolve(st);
@ -227,7 +270,48 @@ module.exports = {
// Var calJson = [];
}
}, getAdvancedCalV3: function(url) {
'use strict';
var self = this;
return new Promise(function(resolve, reject) {
try {
request(url, function(err, res, body) {
if (err) {
// logger.error(err);
return reject(err);
// Throw err;
}
self.jsonBlock = processICAL(body);
// logger.debug(self.jsonBlock);
var st = self.getTodaysSimple().entries;
var tom = self.getTomorrow().entries;
var week = self.getWeek().entries;
var obj = {today:st, tomorrow:tom, week:week};
logger.debug(obj);
return resolve(obj);
}, function(error, response, body) {
if (response.statusCode !== 200) {
logger.error(response.statusCode);
logger.error(body);
return reject(error);
}
});
} catch (e) {
console.log(e);
return reject(e);
}
});
// Var calJson = [];
}