Created
June 17, 2013 16:20
-
-
Save cantlin/5798166 to your computer and use it in GitHub Desktop.
This file contains 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
// Convert an HSBC "previous statement" page into a CSV | |
var year = 2013, | |
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | |
var output = '', | |
rows = $('table').last().find('tr'); | |
rows.each(function(i, row) { | |
if(i === 1 || i === rows.length - 1) return; | |
var cells = $(row).find('td'); | |
var date = $(cells[0]).text().trim(), | |
desc = $(cells[2]).text().trim(), | |
debited = $(cells[3]).text().trim() | |
credited = $(cells[4]).text().trim(); | |
// Reformat date | |
var day = date.split(' ')[0], | |
month = months.indexOf(date.split(' ')[1]); | |
date = (new Date(year, month, day)).toISOString().split('T')[0]; | |
var transaction = ''; | |
if(debited === "") { | |
transaction = credited; | |
} else { | |
transaction = '-' + debited; | |
} | |
output += [date, desc, transaction].join(',') + "\n" | |
}); | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment