Created
June 30, 2014 20:29
-
-
Save adamscybot/76a15900ab6b2515337d to your computer and use it in GitHub Desktop.
Retrieve total balance of student loan from student finance direct pages
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
// First go to https://secure.studentfinance.direct.gov.uk/ and log in. | |
// Now go to https://secure.studentfinance.direct.gov.uk/customer/payments/view?service=direct/1/Home/listPayments_TablePages.pages_linkPage&sp=AHome%2FlistPayments_TableView&sp=1 | |
// Now open the console and put in: | |
// | |
// var jq = document.createElement('script'); | |
// jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"; | |
// document.getElementsByTagName('head')[0].appendChild(jq); | |
// jQuery.noConflict(); | |
// | |
// Press enter. | |
// Now copy all the below into console. | |
// Press enter. | |
// | |
// Rough as hell and messy script. Why the hell isnt the balance total on the website?! | |
var totalLoan = 0; | |
var totalGrant = 0; | |
var promises = []; | |
var pageMax = parseInt(jQuery('#paymentsTable tr:last-child span a:nth-last-of-type(2)').text()); | |
for(var page=1;page<=pageMax;page++) { | |
promises.push(jQuery.get('https://secure.studentfinance.direct.gov.uk/customer/payments/view?service=direct/1/Home/listPayments_TablePages.pages_linkPage&sp=AHome%2FlistPayments_TableView&sp='+page, function (content) { | |
var dates = jQuery('#paymentsTable tr:nth-of-type(N+3):not(:last-child) td:nth-of-type(3)').map(function(i,v) { | |
return jQuery(this).text(); | |
}).toArray(); | |
var products = jQuery('#paymentsTable tr:nth-of-type(N+3):not(:last-child) td:nth-of-type(4)').map(function(i,v) { | |
return jQuery(this).text(); | |
}).toArray(); | |
var amounts = jQuery('#paymentsTable tr:nth-of-type(N+3):not(:last-child) td:nth-of-type(6)').map(function(i,v) { | |
return jQuery(this).text(); | |
}).toArray(); | |
for(var i=0;i<amounts.length;i++) { | |
console.log(dates[i], products[i], amounts[i]); | |
if (products[i].indexOf('Loan') !== -1) { | |
totalLoan += parseFloat(amounts[i].substring(1)); | |
} else if (products[i].indexOf('Grant') !== -1) { | |
totalGrant += parseFloat(amounts[i].substring(1)); | |
} | |
} | |
})); | |
} | |
jQuery.when.apply(jQuery, promises).then(function(schemas) { | |
console.log("TOTAL LOAN: "+totalLoan); | |
console.log("TOTAL GRANT: "+totalGrant); | |
}, function(e) { | |
console.log("Couldnt fetch a page"); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment