Skip to content

Instantly share code, notes, and snippets.

@interlock
Created May 23, 2012 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interlock/2777147 to your computer and use it in GitHub Desktop.
Save interlock/2777147 to your computer and use it in GitHub Desktop.
Get notified when the game status changes on SaskatoonUltimate.org
// install some dependencies
// npm install jsdom request growler
//
// run: node scrape.js
var jsdom = require('jsdom'),
request = require('request'),
growler = require('growler');
console.log('init');
var status = false;
var myApp = new growler.GrowlApplication('Ultimate Scraper');
myApp.setNotifications({
'Changed': {}
});
myApp.register();
function checkit() {
console.log('requesting');
request({uri: 'http://saskatoonultimate.org/'}, function(err,response,body) {
console.log('request got');
var self = this;
self.items = new Array();
if ( err && response.statusCode !== 200 ) { console.log("Request error"); }
jsdom.env({
html: body,
scripts: ['http://code.jquery.com/jquery-1.6.min.js']
}, function(err, window) {
var $ = window.jQuery;
var new_status = $('#block-block-5').find('p').html();
if ( status == false ) {
status = new_status;
console.log('first status: ' + status);
myApp.sendNotification('Changed', {
title: 'Ultimate Scaper Started',
text: status,
sticky: true
});
} else if ( status != new_status ) {
console.log('changed');
myApp.sendNotification('Changed', {
title: 'Ultimate Scaper Change',
text: status,
sticky: true
});
}
});
});
setTimeout(checkit, 30000 );
}
checkit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment