Skip to content

Instantly share code, notes, and snippets.

@protozoo
Created May 29, 2015 11:44
Show Gist options
  • Save protozoo/f19ad39bccadc69fefb1 to your computer and use it in GitHub Desktop.
Save protozoo/f19ad39bccadc69fefb1 to your computer and use it in GitHub Desktop.
Website content changes monitor
// Required libraries. In OSX you may also need terminal-notifier (sudo gem install terminal-notifier)
var opener = require('opener');
var request = require('request');
var cheerio = require('cheerio');
var notifier = require('node-notifier');
// Settings
var url = 'http://www.beachhousebaltimore.com/';
var town = "Barcelona";
var timeIntervalInSeconds = 60;
// Start tracking at time intervals
setInterval( function(){
// Get the website
request(url, function(err, resp, body) {
if (err)
throw err;
// find the element we want
$ = cheerio.load(body);
var ticketLink = $( 'li:contains("'+ town +'")' )[0].children[2].attribs.href;
// Get the current time
var now = new Date();
var timestamp = now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();
// Is there a link available?
if( ticketLink != "#" )
{
// Yeah! notify!
console.log( "Tickets link found for "+town+"! ["+timestamp+"]: " + ticketLink );
notifier.notify({
title: 'Beach House watcher',
message: "Hey bro, Beach House Tickets are now AVAILABLE!!! " + ticketLink,
wait: true // wait with callback until user action is taken on notification
}, function (err, response) {} );
// Capture notification click (when notification clicked, open website)
notifier.on('click', function ( notifierObject, options) {
console.log( "Notification clicked, let's go!" );
opener(ticketLink);
});
}else{
// Grrr.... keep waiting..
console.log( "Tickets link NOT found, keep waitting... ["+timestamp+"]" );
}
});
}, timeIntervalInSeconds*1000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment