#!/usr/bin/perl -w # # The landsbanki-kredit2qif.pl is Copyright (c) 2008 Tomas Edwardsson. Iceland. All right reserved. # # You may distribute under the terms of either the GNU General Public License or the Artistic License, # as specified in the Perl README file. # # Þetta forrit tekur html skrá úr kreditkortayfirliti í netbanka Kaupþings og breytir í qif fyrir gnucash eða # önnur forrit sem kunna það snið. # Ferð bara í kreditkortayfirlit í einkabanka landsbankans, gerir save as og fæðir þá skrá inn í þetta forrit. use strict; use HTML::TreeBuilder; die "Usage: $0 " if (@ARGV != 1); my $t = new HTML::TreeBuilder; $t->parse_file($ARGV[0]); my @tables = $t->look_down("_tag" => "table"); die "Too many tables, format changed?" if (@tables > 1); my @tbodies = $tables[0]->look_down("_tag" => "tbody"); my @trs = $tbodies[0]->look_down("_tag" => "tr"); my $type = ''; my %transactions; foreach my $tr (@trs) { if ($tr->{'class'} eq 'hdr') { $type = $tr->look_down("_tag" => "th")->as_text(); } else { #print $tr->{'class'} . "\n"; my @tds = $tr->look_down("_tag" => "td"); next if ($tds[0]->as_text() !~ /(\d{2})\.(\d{2})\.(\d{4})/); my $date = "$3-$2-$1"; my $desc = $tds[2]->as_text(); my $amount = $tds[4]->as_text(); $amount =~ s/\.//g; $amount =~ s/,/./g; $amount =~ s/ ISK//g; $amount *= -1 if ($type ne 'Innborganir'); push @{$transactions{$date}}, { 'desc' => $desc, 'amount' => $amount }; } } foreach my $date (sort keys %transactions) { foreach my $t (@{$transactions{$date}}) { printf("!Type:Bank\nD%s\nP%s\nT%s\n^\n", $date, $t->{desc}, $t->{amount}); } }