From 17bb4114c3d0d24b16c81a158be3941f13822ac6 Mon Sep 17 00:00:00 2001 From: martind2000 Date: Sat, 13 Feb 2016 18:07:20 +0000 Subject: [PATCH] added tech history to today --- .gitignore | 4 +++- lib/today.js | 43 ++++++++++++++++++++++++++++++++++++++++++- package.json | 3 ++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d3f11de..56877ed 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ # https://help.github.com/articles/ignoring-files # Example .gitignore files: https://github.com/github/gitignore /bower_components/ -/node_modules/ \ No newline at end of file +/node_modules/ +.idea +/.idea diff --git a/lib/today.js b/lib/today.js index ab8b330..c230ccb 100644 --- a/lib/today.js +++ b/lib/today.js @@ -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(); \ No newline at end of file diff --git a/package.json b/package.json index 161e78d..5617566 100644 --- a/package.json +++ b/package.json @@ -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",