Skip Menu |

This queue is for tickets about the Finance-Bank-Natwest CPAN distribution.

Report information
The Basics
Id: 11187
Status: open
Priority: 0/
Queue: Finance-Bank-Natwest

People
Owner: knew [...] cpan.org
Requestors: noodles [...] earth.li
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Add support for (mini)statements.
The attached patch allows me to retrieve both the ministatements and full statements from the web interface. I've only been able to test it with a single RBoS account though, so I don't know if it'll work without changes for Natwest or how to cope with multiple accounts.
diff -ruN Finance-Bank-Natwest-0.05.orig/lib/Finance/Bank/Natwest.pm Finance-Bank-Natwest-0.05/lib/Finance/Bank/Natwest.pm --- Finance-Bank-Natwest-0.05.orig/lib/Finance/Bank/Natwest.pm 2005-01-22 11:38:10.000000000 +0000 +++ Finance-Bank-Natwest-0.05/lib/Finance/Bank/Natwest.pm 2005-01-22 12:09:32.000000000 +0000 @@ -128,6 +128,75 @@ return wantarray ? @{$self->{data}{accounts}} : $self->{data}{accounts}; } +sub ministmt { + my $self = shift; + + return unless defined wantarray; + + return wantarray ? @{$self->{data}{ministmt}} : $self->{data}{ministmt}; +} + +sub statement { + my $self = shift; + my ($translist) = + ($self->{connection}->post("Statements.asp?0") =~ + /go to bottom<\/a><\/div>(.*?)<\/form>/s); + + my (@transactions, $stream, $token); + + $stream = HTML::TokeParser->new(\$translist) or croak "$!, stopped"; + + $stream->get_tag("tr"); + while ($token = $stream->get_tag("tr") and exists $token->[1]{class}) { + + $token = $stream->get_tag("td"); + $stream->get_tag("nobr"); + my $date = $stream->get_trimmed_text("/nobr"); + + $stream->get_tag("td"); + my $type = $stream->get_trimmed_text("/td"); + + $stream->get_tag("td"); + my $desc = $stream->get_trimmed_text("/td"); + + $stream->get_tag("td"); + my $in = $stream->get_trimmed_text("/td"); + $in =~ s/&nbsp;/0/; + $in =~ s/\xa3//; + $in =~ s/\xa0//g; + $in =~ s/,//g; + if ($in eq '') { + $in = 0; + } + + $stream->get_tag("td"); + my $out = $stream->get_trimmed_text("/td"); + $out =~ s/&nbsp;/0/; + $out =~ s/\xa3//; + $out =~ s/\xa0//g; + $out =~ s/,//g; + + $stream->get_tag("td"); + my $bal = $stream->get_trimmed_text("/td"); + $bal =~ s/&nbsp;/0/; + $bal =~ s/\xa3//; + $bal =~ s/\xa0//g; + $bal =~ s/,//g; + + + push @transactions, { + date => $date, + type => $type, + desc => $desc, + in => $in, + out => $out, + bal => $bal + }; + } + + return @transactions; +} + sub _load_accounts { my $self = shift; @@ -136,6 +205,7 @@ /<form.*?>(.*?)<\/form>(.*?)<div class="smftr">/s); $self->{data}{accounts} = $self->_process_accountlist($accountlist); + $self->{data}{ministmt} = $self->_process_ministmt($ministmt); } @@ -152,7 +222,7 @@ my $name = $stream->get_trimmed_text("/td"); $stream->get_tag("td"); $stream->get_tag("span"); - $name =~ s/\xa0+/ /; + $name =~ s/\xa0+/ /g; $name =~ s/^\s+//; $name =~ s/\s+$//; @@ -184,6 +254,52 @@ return \@accounts; }; +sub _process_ministmt{ + my ($self, $ministmt) = @_; + my (@transactions, $stream, $token); + + $stream = HTML::TokeParser->new(\$ministmt) or croak "$!, stopped"; + + $stream->get_tag("table"); + $stream->get_tag("table"); + $stream->get_tag("tr"); + while ($token = $stream->get_tag("tr") and exists $token->[1]{class}) { + $token = $stream->get_tag("td"); + $stream->get_tag("nobr"); + + my $date = $stream->get_trimmed_text("/nobr"); + + $stream->get_tag("td"); + my $type = $stream->get_trimmed_text("/td"); + + $stream->get_tag("td"); + my $desc = $stream->get_trimmed_text("/td"); + + $stream->get_tag("td"); + my $in = $stream->get_trimmed_text("/td"); + $in =~ s/\&nbsp;/0/; + $in =~ s/\xa3//; + $in =~ s/,//g; + + $stream->get_tag("td"); + my $out = $stream->get_trimmed_text("/td"); + $out =~ s/\&nbsp;/0/; + $out =~ s/\xa3//; + $out =~ s/,//g; + + push @transactions, { + date => $date, + type => $type, + desc => $desc, + in => $in, + out => $out, + }; + } + + return \@transactions; +}; + + 1; __END__