Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewfinnell/29d85176a9a69eec753df21bb481dd96 to your computer and use it in GitHub Desktop.
Save andrewfinnell/29d85176a9a69eec753df21bb481dd96 to your computer and use it in GitHub Desktop.
scanner.js
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