added tech history to today

This commit is contained in:
martind2000 2016-02-13 18:07:20 +00:00
parent 1c84148af2
commit 17bb4114c3
3 changed files with 47 additions and 3 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
# Example .gitignore files: https://github.com/github/gitignore
/bower_components/
/node_modules/
.idea
/.idea

View File

@ -4,6 +4,8 @@
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');
var log4js = require('log4js');
var logger = log4js.getLogger();
var todayCache = {
last: 0,
@ -66,6 +68,39 @@ module.exports = {
res.render('pages/today', todayCache);
},
getTechHistory: function () {
var url, d, day, month, monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
d = new Date();
month = monthNames[d.getMonth()];
day = d.getDate();
url = ['http://www.computerhistory.org/tdih/', month, '/', day].join('');
logger.info(url);
request(url, function (err, resp, body) {
if (err)
throw err;
$ = cheerio.load(body);
var tdihbody = $('#tdihbody');
var output = [];
tdihbody.find('.tdihevent > p').each(function (div) {
logger.info($(this));
var s = $(this).text();
if (s.indexOf('Today\'s recipe:') == -1) {
output.push(s);
}
});
todayCache.data.history = todayCache.data.history.concat(output);
console.log(todayCache.data.history);
});
},
getHistory: function () {
var url, d, day, month, monthNames = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
@ -76,6 +111,9 @@ module.exports = {
day = d.getDate();
url = ['http://www.bbc.co.uk/scotland/history/onthisday/', month, '/', day].join('');
todayCache.data.history = [];
console.log(url);
request(url, function (err, resp, body) {
if (err)
@ -95,6 +133,7 @@ module.exports = {
todayCache.data.history = output;
console.log(todayCache.data.history);
module.exports.getTechHistory();
});
},
@ -233,7 +272,8 @@ setTimeout(function () {
setTimeout(function () {
// console.log('Pre loading trains...');
module.exports.getHistory();
module.exports.getHistory();
}, 25000);
@ -257,3 +297,4 @@ cron.schedule('0 7 * * *', function () {
});
module.exports.getHistory();

View File

@ -9,6 +9,8 @@
"htmlparser": "^1.7.7",
"jade": "^1.11.0",
"jsonfile": "^2.2.3",
"lodash": "^4.3.0",
"log4js": "^0.6.31",
"mammoth": "^0.3.25-pre.1",
"request": "^2.67.0",
"simple-weather": "^1.2.2",
@ -16,7 +18,6 @@
},
"dependencies": {
"express": "3.x",
"lodash": "^4.3.0",
"node-cron": "^1.0.0",
"scrape": "^0.2.3",
"ultrases": "^0.1.3",