Skip to content

Instantly share code, notes, and snippets.

@mockee
Created May 5, 2012 15:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mockee/2603242 to your computer and use it in GitHub Desktop.
Save mockee/2603242 to your computer and use it in GitHub Desktop.
Check the price of Ctrip tourism product
var http = require('http'),
jsdom = require('jsdom'),
nodemailer = require('nodemailer');
smtpTransport = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: 'username@gmail.com',
pass: 'password'
}
}),
mailOptions = {
from: 'Sender Name <sender@gmail.com>',
to: 'receiver1@gmail.com, receiver2@gmail.com'
},
domConfig = {
html: 'http://vacations.ctrip.com/freetravel/p68002s1.html',
features: { QuerySelector: true },
done: function (errors, window) {
var doc = window.document,
listPrice = 5545,
travelDate = '2012-05-26',
title = doc.querySelector('h2').textContent,
price = window.$$.module.pageData
.lines[0].dateInfo[travelDate][0];
if (price !== listPrice) {
mailOptions.subject = '[价格有变] ' + title;
mailOptions.text = travelDate + ' 价格: RMB ' + price;
smtpTransport.sendMail(mailOptions, function (err, res) {
if (err) { console.error(err); }
else { console.info('邮件已发送!'); }
});
} else {
console.info('价格没有变动:(');
}
}
};
setInterval(function() {
jsdom.env(domConfig);
}, 1000 * 60 * 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment