added archiving to today

This commit is contained in:
Martin Donnelly 2016-03-24 17:09:42 +00:00
parent c564a7db6f
commit db37320e4c
3 changed files with 57 additions and 4 deletions

27
db/maker.js Normal file
View File

@ -0,0 +1,27 @@
var nano = require('nano')('http://localhost:5984');
// clean up the database we created previously
nano.db.destroy('silvrgit', function () {
// create a new database
nano.db.create('silvrgit', function () {
// specify the database we are going to use
var keeper = nano.use('silvrgit');
// and insert a document in it
/* keeper.insert({ crazy: true }, 'rabbit', function(err, body, header) {
if (err) {
console.log('[alice.insert] ', err.message);
return;
}
console.log('you have inserted the rabbit.')
console.log(body);
});*/
});
});
/**
* Created by Martin on 02/03/2016.
*/

View File

@ -8,11 +8,17 @@ var jade = require('jade'), _ = require('lodash'), dateFormat = require(
'dateformat');
var jsonfile = require('jsonfile'), fs = require('fs'), STRING = require(
'string');
var nano = require('nano')('http://localhost:5984');
var log4js = require('log4js');
var logger = log4js.getLogger();
var calHandler = require('./calHandler');
var swedishWord = require('./swedishword');
var db_name = 'silvrgit';
var dbCouch = nano.use(db_name);
var todayCache = {
last: 0, data: {
trains: {last: 0, data: []},
@ -59,6 +65,18 @@ function saveData() {
jsonfile.writeFileSync(file, todayCache);
}
function saveToDB(data) {
logger.debug('Inserting into couch...');
// logger.info(util.inspect(obj));
dbCouch.insert(data, function (err, body, header) {
if (err) {
logger.error('Error inserting into couch');
logger.error(err);
return;
}
});
}
function nth(d) {
if (d > 3 && d < 21) return 'th'; // thanks kennebec
switch (d % 10) {
@ -81,6 +99,11 @@ function dayNumber() {
return Math.floor(diff / oneDay);
}
function breakDay() {
var now = new Date();
return {year:now.getFullYear(), month:parseInt(now.getMonth()) + 1, day:now.getDate()}
}
/**
* @return {number}
*/
@ -436,6 +459,7 @@ module.exports = {
logger.error(e);
}
todayCache.date = breakDay();
// word of the day http://wotd.transparent.com/rss/swedish-widget.xml?t=1455840000000
// time stamp
@ -497,9 +521,9 @@ setTimeout(function() {
module.exports.preLoadToday();
}, 15000);
/*setTimeout(function () {
sendEmailV1();
}, 45000);*/
setTimeout(function () {
saveToDB(todayCache);
}, 45000);
cron.schedule('45 6 * * *', function() {
module.exports.preLoadToday();
@ -513,6 +537,7 @@ cron.schedule('0 */1 * * *', function() {
cron.schedule('0 7 * * *', function() {
sendEmailV1();
saveToDB(todayCache);
// console.log('tick');
return -1;
});

View File

@ -12,6 +12,7 @@
"lodash": "^4.3.0",
"log4js": "^0.6.31",
"mammoth": "^0.3.25-pre.1",
"nano": "^6.2.0",
"request": "^2.67.0",
"simple-weather": "^1.2.2",
"wordsoap": "^0.2.0",