Updated to include history
This commit is contained in:
parent
6f95baaa7a
commit
9897261108
1
.gitignore
vendored
1
.gitignore
vendored
@ -180,3 +180,4 @@ xcuserdata
|
||||
dist
|
||||
/jspm_packages/npm/
|
||||
/jspm_packages/github/
|
||||
!/scratch/
|
||||
|
31
index.js
31
index.js
@ -2,11 +2,15 @@ const sentence = require('to-sentence-case');
|
||||
const UltraSES = require('ultrases');
|
||||
const dateFormat = require('dateformat');
|
||||
const pug = require('pug');
|
||||
const cron = require('node-cron');
|
||||
const LocalStorage = require('node-localstorage').LocalStorage;
|
||||
const logger = require('log4js').getLogger('menuizer');
|
||||
logger.level = 'debug';
|
||||
|
||||
// {'name':'', 'url':''
|
||||
|
||||
localStorage = new LocalStorage('./scratch');
|
||||
|
||||
const email = require('smtp-email-sender')({
|
||||
'host': 'mail.caliban.io',
|
||||
'port': '465',
|
||||
@ -162,26 +166,43 @@ function pugTest(data, newpath) {
|
||||
logger.debug(pug.renderFile( `${newpath }/` + 'pug/email.pug', data));
|
||||
}
|
||||
|
||||
(function () {
|
||||
function doJob() {
|
||||
// body
|
||||
const _history = localStorage.getItem('history');
|
||||
let history = [];
|
||||
if (_history !== null)
|
||||
history = JSON.parse(_history);
|
||||
|
||||
const usedNumbers = [];
|
||||
const suggestions = [];
|
||||
const data = {};
|
||||
const now = new Date();
|
||||
var options = { 'weekday': 'long', 'year': 'numeric', 'month': 'long', 'day': 'numeric' };
|
||||
const options = { 'weekday': 'long', 'year': 'numeric', 'month': 'long', 'day': 'numeric' };
|
||||
do {
|
||||
const randomnumber = Math.floor(Math.random() * menu.length);
|
||||
if (usedNumbers.indexOf(randomnumber) === -1) {
|
||||
if (usedNumbers.indexOf(randomnumber) === -1 && history.indexOf(randomnumber) === -1) {
|
||||
usedNumbers.push(randomnumber);
|
||||
suggestions.push(menu[randomnumber]);
|
||||
history.push(randomnumber);
|
||||
}
|
||||
} while(usedNumbers.length < 5);
|
||||
|
||||
data.ts = now.toLocaleDateString('en-GB', options);
|
||||
data.suggestions = suggestions;
|
||||
|
||||
// logger.debug(JSON.stringify(data));
|
||||
localStorage.setItem('history', JSON.stringify(history.slice(history.length - 20)));
|
||||
|
||||
sendSMTP(data, './');
|
||||
}());
|
||||
|
||||
logger.debug(`Done:${data.ts}`);
|
||||
}
|
||||
|
||||
/* (function() {
|
||||
doJob();
|
||||
}());*/
|
||||
|
||||
cron.schedule('0 8 * * 6', function () {
|
||||
doJob();
|
||||
|
||||
return -1;
|
||||
});
|
||||
|
52
package-lock.json
generated
52
package-lock.json
generated
@ -387,6 +387,11 @@
|
||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz",
|
||||
"integrity": "sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q="
|
||||
},
|
||||
"imurmurhash": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz",
|
||||
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o="
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
@ -488,6 +493,11 @@
|
||||
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz",
|
||||
"integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4="
|
||||
},
|
||||
"localstorage": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/localstorage/-/localstorage-1.0.1.tgz",
|
||||
"integrity": "sha512-2L2RX3vh0lEARtDglRKxazh8lHCR6PGAZOsFXXpfkYr976WHcQS3xdriKhVzJLf3+GCmxvMkTtoDl0eCfg/3eQ=="
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
@ -535,6 +545,23 @@
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node-cron": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-2.0.3.tgz",
|
||||
"integrity": "sha512-eJI+QitXlwcgiZwNNSRbqsjeZMp5shyajMR81RZCqeW0ZDEj4zU9tpd4nTh/1JsBiKbF8d08FCewiipDmVIYjg==",
|
||||
"requires": {
|
||||
"opencollective-postinstall": "^2.0.0",
|
||||
"tz-offset": "0.0.1"
|
||||
}
|
||||
},
|
||||
"node-localstorage": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/node-localstorage/-/node-localstorage-1.3.1.tgz",
|
||||
"integrity": "sha512-NMWCSWWc6JbHT5PyWlNT2i8r7PgGYXVntmKawY83k/M0UJScZ5jirb61TLnqKwd815DfBQu+lR3sRw08SPzIaQ==",
|
||||
"requires": {
|
||||
"write-file-atomic": "^1.1.4"
|
||||
}
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.7.0.tgz",
|
||||
@ -609,6 +636,11 @@
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||
},
|
||||
"opencollective-postinstall": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz",
|
||||
"integrity": "sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw=="
|
||||
},
|
||||
"optimist": {
|
||||
"version": "0.3.7",
|
||||
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.3.7.tgz",
|
||||
@ -894,6 +926,11 @@
|
||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz",
|
||||
"integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o="
|
||||
},
|
||||
"slide": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz",
|
||||
"integrity": "sha1-VusCfWW00tzmyy4tMsTUr8nh1wc="
|
||||
},
|
||||
"smtp-connection": {
|
||||
"version": "2.12.0",
|
||||
"resolved": "https://registry.npmjs.org/smtp-connection/-/smtp-connection-2.12.0.tgz",
|
||||
@ -1010,6 +1047,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"tz-offset": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/tz-offset/-/tz-offset-0.0.1.tgz",
|
||||
"integrity": "sha512-kMBmblijHJXyOpKzgDhKx9INYU4u4E1RPMB0HqmKSgWG8vEcf3exEfLh4FFfzd3xdQOw9EuIy/cP0akY6rHopQ=="
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "2.8.29",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz",
|
||||
@ -1112,6 +1154,16 @@
|
||||
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
|
||||
"integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc="
|
||||
},
|
||||
"write-file-atomic": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz",
|
||||
"integrity": "sha1-+Aek8LHZ6ROuekgRLmzDrxmRtF8=",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.11",
|
||||
"imurmurhash": "^0.1.4",
|
||||
"slide": "^1.1.5"
|
||||
}
|
||||
},
|
||||
"xml2js": {
|
||||
"version": "0.4.19",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
|
||||
|
@ -10,7 +10,10 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"localstorage": "^1.0.1",
|
||||
"log4js": "^5.1.0",
|
||||
"node-cron": "^2.0.3",
|
||||
"node-localstorage": "^1.3.1",
|
||||
"pug": "^2.0.4",
|
||||
"smtp-email-sender": "^1.0.0",
|
||||
"to-sentence-case": "^1.0.0",
|
||||
|
Loading…
Reference in New Issue
Block a user