Created
October 10, 2010 02:29
-
-
Save chapel/618859 to your computer and use it in GitHub Desktop.
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
var httpAgent = require('http-agent'), | |
jsdom = require('jsdom'), | |
url = require('url'), | |
sys = require('sys'); | |
exports.start = function () { | |
var agent = httpAgent.create('www.bungie.net', ['/stats/reach/playergamehistory.aspx?player=thechapel&vc=2']); | |
agent.addListener('next', function (err, agent) { | |
//console.log(agent.body); | |
var uri = url.parse(agent.url.toLowerCase()); | |
//console.log(uri); | |
exports.dispatch(uri, agent); | |
}); | |
agent.addListener('stop', function (err, agent) { | |
sys.puts('the agent has stopped'); | |
}); | |
agent.start(); | |
}; | |
exports.dispatch = function (uri, agent) { | |
switch (uri.pathname) { | |
case '/stats/reach/playergamehistory.aspx': | |
exports.playergamehistory(agent); | |
break; | |
case '/stats/reach/gamestats.aspx': | |
exports.gamestats(agent); | |
break; | |
} | |
}; | |
exports.playergamehistory = function (agent) { | |
var window = jsdom.jsdom(agent.body).createWindow(); | |
jsdom.jQueryify(window, './jquery.js', function (window, jquery) { | |
window.jQuery('a[id$=hypGame]').each(function () { | |
agent.addUrl(this.href); | |
}); | |
agent.next(); | |
}); | |
}; | |
exports.jqwindow = function(agent, ratingSel, userSel, callback) { | |
var window = jsdom.jsdom(agent.body).createWindow(); | |
jsdom.jQueryify(window, './jquery.js', function (window, jquery) { | |
var ratings = []; | |
var userRating; | |
window.jQuery(ratingSel).each(function () { | |
ratings.push(this.innerHTML.trim()); | |
}); | |
console.log(window.jQuery(userSel).length); | |
window.jQuery(userSel).each(function () { | |
console.log(this.innerHTML.trim()); | |
userRating = this.innerHTML.trim(); | |
}); | |
callback (ratings, userRating); | |
}); | |
} | |
exports.gamestats = function (agent) { | |
ratingValue = function (ratings, userRating) { | |
ratings.sort(compare); | |
console.log(ratings.indexOf(userRating)); | |
} | |
exports.jqwindow(agent, 'td[id$=arenaRating]', '.current_selected_player_row td[id$=arenaRating]', ratingValue); | |
agent.next(); | |
function compare(a,b){ | |
return b-a; | |
}; | |
} | |
exports.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment