Skip to content

Instantly share code, notes, and snippets.

@pauljamesrussell
Created April 22, 2012 22:42
Show Gist options
  • Save pauljamesrussell/2467362 to your computer and use it in GitHub Desktop.
Save pauljamesrussell/2467362 to your computer and use it in GitHub Desktop.
A quick ruby script to take HTML exported from oneaccount.com and convert it to a CSV file of transactions for online banking.
# Usage: ruby one_account_to_csv.rb < html_dump.html > transactions.csv
# First row has column titles.
$text = readlines.join
puts "Date,Type,Merchant,Debit,Credit"
$text.scan %r{<tr class="content">.*?</tr>}m do |line|
unless line =~ /colspan="5"/
values = line.scan(%r{<td.*?>(?:<[^/].*?>)*(.*?)</}).map {|v| v.first}
values.each do |value|
value.gsub!(%r{<br>}," - ")
value.gsub! /&nbsp;/, " "
value.tr!(',','')
end
puts values.join ","
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment