Skip to content

Instantly share code, notes, and snippets.

@chapel
Forked from indexzero/arena
Created October 7, 2010 10:42
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 chapel/614942 to your computer and use it in GitHub Desktop.
Save chapel/614942 to your computer and use it in GitHub Desktop.
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, selector, callback) {
var window = jsdom.jsdom(agent.body).createWindow();
jsdom.jQueryify(window, './jquery.js', function (window, jquery) {
var query = [];
window.jQuery(selector).each(function () {
query.push(this.innerHTML.trim());
});
callback (query);
});
}
exports.gamestats = function (agent) {
ratings = function (query) {
console.log(query);
}
selected = function (query) {
console.log(query);
}
exports.jqwindow(agent, 'td[id$=arenaRating]', ratings);
//ratings.sort(compare);
exports.jqwindow(agent, 'a[id$=gamertagHyperLink]', selected);
//console.log(selected.query, ratings.query);
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