Created
May 29, 2014 02:55
-
-
Save brettwooldridge/f974328fd7116795d853 to your computer and use it in GitHub Desktop.
scanner.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path') | |
var childProcess = require('child_process') | |
var phantomjs = require('phantomjs') | |
var nodemailer = require("nodemailer"); | |
// create reusable transport method (opens pool of SMTP connections) | |
var smtpTransport = nodemailer.createTransport("SMTP",{ | |
service: "Gmail", | |
auth: { | |
user: "br****@gmail.com", | |
pass: "*******" | |
} | |
}); | |
// setup e-mail data with unicode symbols | |
var mailOptions = { | |
from: "Brett ***** <br*******@gmail.com>", | |
to: "br*****@gmail.com", | |
subject: "Refurbished iMac available", | |
text: "http://store.apple.com/jp/browse/home/specialdeals/mac/imac/27" | |
} | |
var binPath = phantomjs.path | |
var childArgs = [ | |
path.join(__dirname, 'imac.js') | |
] | |
setInterval(checkApple, 30000); | |
function checkApple() { | |
childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) { | |
var pattern = /Match/i; | |
if (!stdout.match(pattern)) { | |
console.log('Checked at ' + getDateTime()); | |
return; | |
} | |
console.log('Got ' + stdout.trim() + ' ... sending email'); | |
smtpTransport.sendMail(mailOptions, function(error, response){ | |
if (error){ | |
console.log(error); | |
} else { | |
console.log("Message sent: " + response.message); | |
} | |
// if you don't want to use this transport object anymore, uncomment following line | |
smtpTransport.close(); // shut down the connection pool, no more messages | |
}); | |
}); | |
} | |
function getDateTime() { | |
var date = new Date(); | |
var hour = date.getHours(); | |
hour = (hour < 10 ? "0" : "") + hour; | |
var min = date.getMinutes(); | |
min = (min < 10 ? "0" : "") + min; | |
var sec = date.getSeconds(); | |
sec = (sec < 10 ? "0" : "") + sec; | |
var year = date.getFullYear(); | |
var month = date.getMonth() + 1; | |
month = (month < 10 ? "0" : "") + month; | |
var day = date.getDate(); | |
day = (day < 10 ? "0" : "") + day; | |
return year + ":" + month + ":" + day + " - " + hour + ":" + min + ":" + sec; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment