Created
May 23, 2012 19:09
-
-
Save interlock/2777147 to your computer and use it in GitHub Desktop.
Get notified when the game status changes on SaskatoonUltimate.org
This file contains hidden or 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
// 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