From f7e17b02deba57f097bb3288ead62370d4b1e7e3 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 11 Feb 2016 11:40:10 +0000 Subject: [PATCH] cron for today to send emails --- .idea/encodings.xml | 6 +++++ .idea/modules.xml | 8 ++++++ .idea/silvrgit.iml | 8 ++++++ .idea/vcs.xml | 6 +++++ app/app.js | 6 ++--- lib/jade/today.jade | 28 ++++++++++++++++++++ lib/password.js | 12 +++------ lib/today.js | 59 ++++++++++++++++++++++++++++++++++++++++--- package.json | 5 ++++ views/pages/slack.ejs | 3 ++- 10 files changed, 124 insertions(+), 17 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/silvrgit.iml create mode 100644 .idea/vcs.xml create mode 100644 lib/jade/today.jade diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..66dc2e8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/silvrgit.iml b/.idea/silvrgit.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/silvrgit.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/app.js b/app/app.js index 41a3c27..1f11a60 100644 --- a/app/app.js +++ b/app/app.js @@ -22,9 +22,9 @@ }, { title: 'Ends', - y: 2015, + y: 2016, m: 4, - d: 10 + d: 4 }]; var addDays = function (myDate, days) { return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000); @@ -45,7 +45,7 @@ var third = new Date(); start101.setFullYear(2013, 9, 24); end101 = addDays(start101, 1001); - endContract.setFullYear(2015, 4, 10); + endContract.setFullYear(2016, 4, 4); third.setFullYear(2013, 7, 25); $('#one').text('101B ends: ' + Math.ceil(getDays(today, end101)) + " days / " + Math.ceil(getDays(today, diff --git a/lib/jade/today.jade b/lib/jade/today.jade new file mode 100644 index 0000000..d2efb01 --- /dev/null +++ b/lib/jade/today.jade @@ -0,0 +1,28 @@ +doctype html +html(lang="en") + head + title= Today + + body + h1 Today + #container.weather + h2 Weather + p Currently: + = ' ' + data.weather.currently + p Later: + = ' ' + data.weather.today + + if data.weather.alerts.length > 0 + h3 ALERT + each alert in data.weather.alerts + p(style="color:red;")= alert.title + p= alert.description + + #container.weather + if data.trains.data.length > 0 + h2 Trains + each alert in data.trains.data + strong= alert.title + p= alert.description + + \ No newline at end of file diff --git a/lib/password.js b/lib/password.js index 09a6b78..a69f30a 100644 --- a/lib/password.js +++ b/lib/password.js @@ -34,27 +34,21 @@ var left = ["Alabama", "Nevada", "New Hampshire", "New Jersey", - "New Mexico", + "Mexico", "New York", - "North Carolina", - "North Dakota", + "Carolina", + "Dakota", "Ohio", "Oklahoma", "Oregon", "Palau", "Pennsylvania", - "Puerto Rico", - "Rhode Island", - "South Carolina", - "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", - "Virgin Islands", "Virginia", "Washington", - "West Virginia", "Wisconsin", "Wyoming", "Glasgow", diff --git a/lib/today.js b/lib/today.js index 2fd627a..dc300ee 100644 --- a/lib/today.js +++ b/lib/today.js @@ -1,7 +1,8 @@ /** * Created by marti on 30/01/2016. */ -var http = require('http'), request = require('request'), cheerio = require('cheerio'), Forecast = require('forecast.io'), util = require('util'); +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'); var todayCache = { last: 0, @@ -23,6 +24,27 @@ var forecastOptions = { units: 'uk2' }; +var mailer = new UltraSES({ + aws: { + accessKeyId: 'AKIAJWJS75F7WNCGK64A', + secretAccessKey: '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', + "region": "eu-west-1" + }, + defaults: { + from: 'Martin Donnelly ' + } +}); + +Array.prototype.indexOfOld=Array.prototype.indexOf + +Array.prototype.indexOf=function(e,fn){ + if(!fn){return this.indexOfOld(e)} + else{ + if(typeof fn ==='string'){var att=fn;fn=function(e){return e[att];}} + return this.map(fn).indexOfOld(e); + } +}; + module.exports = { getToday: function (req, res) { res.render('pages/today', todayCache); @@ -70,15 +92,16 @@ module.exports = { // join arrays for (var i = 0; i < outputArray.length; i++) { + var p = todayCache.data.trains.data.indexOf(outputArray[i].title); + console.log('P: ' + p); todayCache.data.trains.data.push(outputArray[i]) } + todayCache.data.trains.data = _.uniq(todayCache.data.trains.data); }); todayCache.data.trains.last = now; - // todayCache.data.trains.data = j; - }, updateTrains: function () { console.log('Updating trains..'); @@ -131,8 +154,36 @@ module.exports = { } ; +function sendEmail() { + var email = { + to: 'martind2000@gmail.com', + subject: 'Today' + }; + + + var template = { file: 'jade/today.jade', locals: todayCache }; + mailer.sendTemplate(email, template, function(err){ + if(err) throw err; + console.log('compiled template email sent'); + }); + +/* + var fn = jade.compileFile(template.file); + + console.log(fn(todayCache)); +*/ + +} + + setTimeout(function () { // console.log('Pre loading trains...'); module.exports.preLoadToday(); -}, 15000); \ No newline at end of file +}, 15000); + +cron.schedule('1 00 7 * * *', function(){ + sendEmail(); + // console.log('tick'); + return -1; +}); \ No newline at end of file diff --git a/package.json b/package.json index 2df0db9..d63ac57 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,8 @@ "ejs": "^2.3.4", "forecast.io": "0.0.9", "htmlparser": "^1.7.7", + "jade": "^1.11.0", + "jsonfile": "^2.2.3", "mammoth": "^0.3.25-pre.1", "request": "^2.67.0", "simple-weather": "^1.2.2", @@ -13,7 +15,10 @@ }, "dependencies": { "express": "3.x", + "lodash": "^4.3.0", + "node-cron": "^1.0.0", "scrape": "^0.2.3", + "ultrases": "^0.1.3", "unstyler": "^0.2.2" } } diff --git a/views/pages/slack.ejs b/views/pages/slack.ejs index 1306eab..aea4bd9 100644 --- a/views/pages/slack.ejs +++ b/views/pages/slack.ejs @@ -169,8 +169,9 @@
-
Job Searching
+
Contracting