Created
April 22, 2012 22:42
-
-
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.
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
# 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! / /, " " | |
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