Created
June 11, 2012 00:26
-
-
Save scottheckel/2907835 to your computer and use it in GitHub Desktop.
Halo Weekly/Daily Challenges
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
// Retrieve the Weekly and Daily Challenges for your user account on Halo.Xbox.com | |
// Written by Scott Heckel on June 10th, 2012 | |
// Requires CasperJS (http://casperjs.org) to run | |
// Put your Microsoft Login here | |
var username = "yourusername"; | |
var password = "yourpassword"; | |
var casper = require('casper').create(); | |
var fs = require('fs'); | |
var challenges = []; | |
// Login and get the weekly/daily challenges | |
casper.start('http://halo.xbox.com/', function() { | |
if(this.exists('.header-sign-in')) { | |
this.thenClick('.header-sign-in').then(function(){ | |
this.evaluate(login, { username: username, password: password }); | |
this.thenClick('input[type="submit"]').thenOpen('http://halo.xbox.com/en-us/Career/haloreach/Challenges', function() { | |
challenges = this.evaluate(getChallenges); | |
}); | |
}); | |
} else { | |
this.echo('Halo.Xbox.com may have been changed, we cannot log in.') | |
} | |
}); | |
// Fill in the Xbox.com login | |
function login(username, password) { | |
document.querySelector('input[name="login"]').value = username; | |
document.querySelector('input[name="passwd"]').value = password; | |
} | |
// Get the challenges from the page | |
function getChallenges() { | |
var challenges = document.querySelectorAll('.challenge'); | |
return Array.prototype.map.call(challenges, function(e) { | |
return { | |
title: e.querySelector('.header .content .title').innerHTML, | |
creditValue: e.querySelector('.body .credit-value').innerHTML, | |
description: e.querySelector('.body .description').innerHTML | |
}; | |
}); | |
} | |
casper.run(function() { | |
// Format output and write it | |
var challengesText = Array.prototype.map.call(challenges, function(c) { | |
return c.title + "\n" + c.creditValue + "\n" + c.description + "\n"; | |
}); | |
fs.write("challenges.txt", challengesText.join('\n'), 'w'); | |
this.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment