Last active
August 31, 2015 11:25
-
-
Save iest/a0cd4a0713fe980b5211 to your computer and use it in GitHub Desktop.
HSBC don't let customers download CSVs of transaction prior to 2 months ago. With a little node, we can do it
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
'use strict'; | |
const moment = require('moment') | |
const jsdom = require('jsdom'); | |
const fs = require('fs'); | |
const FILE_NAME = process.argv[2] || './May-Jun.html'; | |
jsdom.env( | |
fs.readFileSync(FILE_NAME).toString(), | |
["http://code.jquery.com/jquery.js"], | |
function (err, window) { | |
const $ = window.$; | |
let arr = ['Date,Payee,Category,Memo,Outflow,Inflow']; | |
// Input: [DD MMM] [Type] [Desc] [Out] [In] | |
const rows = $('tbody tr'); | |
rows.each(function(i, el) { | |
const cells = $(el).children(); | |
const date = moment($(cells[0]).text().trim(), 'DD MMM').year(moment().year()); | |
const desc = $(cells[2]).text().trim(); | |
const out = $(cells[3]).text().trim(); | |
const inn = $(cells[4]).text().trim(); | |
// output [YYYY-MM-DD],[Desc],[empty category],[empty memo],[out],[in] | |
arr.push(`${date.format('DD/MM/YY')},${desc},,,${out},${inn}`); | |
}); | |
fs.writeFileSync(`${FILE_NAME}-processed.csv`, arr.join('\n')); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What?
Turns a HTML file containing a table with the following rows:
[DD MMM] [Type] [Desc] [Out] [In]
into a CSV file with[YYYY-MM-DD],[Desc],[empty category],[empty memo],[out],[in]
. I wrote it for use with YNAB but I'm sure you could use it with other budget software.Usage
HSBChtml2YNABCSV.js
to your desktop or whatevernpm install moment jsdom
node HSBChtml2YNABCSV.js path/to/htmlFile
[name-of-original-file]-processed.html