Skip to content

Instantly share code, notes, and snippets.

@rje
Last active August 29, 2015 14:11
Show Gist options
  • Save rje/4b3c62e2fed10f3395d3 to your computer and use it in GitHub Desktop.
Save rje/4b3c62e2fed10f3395d3 to your computer and use it in GitHub Desktop.
lucario check
var cheerio = require('cheerio');
var request = require('request');
var CronJob = require('cron').CronJob;
var url = 'http://www.toysrus.com/product/index.jsp?productId=54369136&prodFindSrc=search&cp=';
function showResult(text) {
var proc = require('child_process');
if(process.platform === 'darwin')
{
var command = 'osascript -e \'tell app "System Events" to display dialog "' + text + '"\'';
proc.exec(command, function(errr, stdout, stderr) {});
}
else
{
proc.exec('msg "%username%" /time:99999 ' + text, function(errr, stdout, stderr) {});
}
}
function parseHTML(err, resp, html) {
if(err) {
showResult(err);
return console.error(err);
}
var parsedHTML = cheerio.load(html);
var node = parsedHTML('#cartAddition');
if(!node.hasClass('disabled')) {
showResult("GO BUY LUCARIO");
}
}
function checkForItem() {
console.log("Performing lucario check");
request(url, parseHTML);
}
function main() {
var job = new CronJob({
cronTime: "*/15 * * * *",
onTick: checkForItem,
start: false
});
job.start();
checkForItem();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment