Created
May 5, 2012 15:18
-
-
Save mockee/2603242 to your computer and use it in GitHub Desktop.
Check the price of Ctrip tourism product
This file contains 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 http = require('http'), | |
jsdom = require('jsdom'), | |
nodemailer = require('nodemailer'); | |
smtpTransport = nodemailer.createTransport('SMTP', { | |
service: 'Gmail', | |
auth: { | |
user: '[email protected]', | |
pass: 'password' | |
} | |
}), | |
mailOptions = { | |
from: 'Sender Name <[email protected]>', | |
to: '[email protected], [email protected]' | |
}, | |
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