| 1 | # $Id: PSK.pm,v 1.8 2004/05/02 12:00:18 florian Exp $ | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Finance::Bank::PSK; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | require 5.005_62; | |||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use WWW::Mechanize; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use HTML::TokeParser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | LOGIN_URL => 'https://wwwtb.psk.at/InternetBanking/sofabanking.html', | |||||||||||||||||||||||||||
| 14 | DETAIL_URL => 'https://wwwtb.psk.at/InternetBanking/InternetBanking/?d=eus&kord=k%011d', | ||||||||||||||||||||||||||||
| 15 | 1 | }; | |||||||||||||||||||||||||||
| 16 | use Class::MethodMaker | ||||||||||||||||||||||||||||
| 17 | 1 | ▶ | new_hash_init => 'new', | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | get_set => [ qw/ account user pass newline _agent / ], | ||||||||||||||||||||||||||||
| 19 | 1 | boolean => 'return_floats'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | our $VERSION = '1.04'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub check_balance { | ||||||||||||||||||||||||||
|
Subroutine
check_balance: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | $self->_connect; | |||||||||||||||||||||||||||
| 28 | 0 | $self->_parse_summary($self->_agent->content); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub get_entries { | ||||||||||||||||||||||||||
|
Subroutine
get_entries: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | $self->_connect; | |||||||||||||||||||||||||||
| 36 | 0 | $self->_agent->get(sprintf(DETAIL_URL, $self->account)); | |||||||||||||||||||||||||||
| 37 | 0 | $self->_agent->submit_form(form_number => 1); | |||||||||||||||||||||||||||
| 38 | 0 | $self->_parse_entries($self->_agent->content); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub _connect { | ||||||||||||||||||||||||||
|
Subroutine
_connect: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | croak "Need account number to connect.\n" unless $self->account; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | croak "Need user to connect.\n" unless $self->user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | croak "Need password to connect.\n" unless $self->pass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return if ref $self->_agent eq 'WWW::Mechanize'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # XXX write tests using the demo account! | ||||||||||||||||||||||||||||
| 52 | #$self->_agent->follow('Demo'); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | $self->_agent(WWW::Mechanize->new); | |||||||||||||||||||||||||||
| 55 | 0 | $self->_agent->agent_alias('Mac Safari'); | |||||||||||||||||||||||||||
| 56 | 0 | $self->_agent->get(LOGIN_URL); | |||||||||||||||||||||||||||
| 57 | 0 | $self->_agent->follow_link(n => 0); | |||||||||||||||||||||||||||
| 58 | 0 | $self->_agent->form_number(1); | |||||||||||||||||||||||||||
| 59 | 0 | $self->_agent->field('tn', $self->account); | |||||||||||||||||||||||||||
| 60 | 0 | $self->_agent->field('vf', $self->user); | |||||||||||||||||||||||||||
| 61 | 0 | $self->_agent->field('pin', $self->pass); | |||||||||||||||||||||||||||
| 62 | 0 | $self->_agent->click('Submit'); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub _parse_entries { | ||||||||||||||||||||||||||
|
Subroutine
_parse_entries: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 67 | 0 | my($self, $content) = @_; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $newline = $self->newline || '; '; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->newline || '; '
MC/DC0%0/1
$self->newline || '; '
$self->newline
Truth table0%0/2
A
A= $self->newline
| |||||||||||||||||||||||||||||
| 69 | 0 | my $stream; | |||||||||||||||||||||||||||
| 70 | my @result; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | $content =~ s/<[Bb][Rr]>/$newline/go; | |||||||||||||||||||||||||||
| 73 | 0 | $stream = HTML::TokeParser->new(\$content); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # find and skip the table heading of the detail listing. | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | for(my $i = 0; $i < 4;) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | my $class = ($stream->get_tag('td'))->[1]{class}; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $i++ if defined $class and $class eq 'theader'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $class and $class eq "theader"
MC/DC0%0/2
defined $class and $class eq "theader"
defined $class
$class eq "theader"
Truth table0%0/3
A and B
A= defined $classB= $class eq "theader"
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # now process the lines... | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | while(my $row = $stream->get_tag('td')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | my $entry; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | last unless | ||||||||||||||||||||||||||||
| 87 | exists $row->[1]{class} and | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $row->[1]{class} eq 'tdata'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $row->[1]{"class"} and $row->[1]{"class"} eq "tdata"
MC/DC0%0/2
exists $row->[1]{"class"} and $row->[1]{"class"} eq "tdata"
exists $row->[1]{"class"}
$row->[1]{"class"} eq "tdata"
Truth table0%0/3
A and B
A= exists $row->[1]{"class"}B= $row->[1]{"class"} eq "tdata"
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # get nr | ||||||||||||||||||||||||||||
| 91 | 0 | $entry->{nr} = $stream->get_text('/td'); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # get text | ||||||||||||||||||||||||||||
| 94 | 0 | $stream->get_tag('td'); | |||||||||||||||||||||||||||
| 95 | 0 | $entry->{text} = $stream->get_text('/td'); | |||||||||||||||||||||||||||
| 96 | 0 | $entry->{text} =~ s/($newline)$//; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # get value date | ||||||||||||||||||||||||||||
| 99 | 0 | $stream->get_tag('td'); | |||||||||||||||||||||||||||
| 100 | 0 | $entry->{value} = $stream->get_text('/td'); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # get amount | ||||||||||||||||||||||||||||
| 103 | 0 | $stream->get_tag('td'); | |||||||||||||||||||||||||||
| 104 | 0 | $entry->{amount} = $stream->get_text('/td'); | |||||||||||||||||||||||||||
| 105 | $entry->{amount} = $self->_scalar2float($entry->{amount}) | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if $self->return_floats; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | push @result, $entry; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | @result; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub _parse_summary { | ||||||||||||||||||||||||||
|
Subroutine
_parse_summary: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 116 | 0 | my($self, $content) = @_; | |||||||||||||||||||||||||||
| 117 | 0 | my $stream = HTML::TokeParser->new(\$content); | |||||||||||||||||||||||||||
| 118 | 0 | my %result; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # get every interesting 'subtitle'. | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | while($stream->get_tag('span')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | my %data; | |||||||||||||||||||||||||||
| 123 | 0 | my $type = $stream->get_trimmed_text('/span'); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # catch girokontos. | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if($type eq 'Girokonto') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 127 | 0 | my $tmp; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # get name, number and currency of the account. | ||||||||||||||||||||||||||||
| 130 | 0 | $stream->get_tag('a'); | |||||||||||||||||||||||||||
| 131 | 0 | $tmp = $stream->get_text('/a'); | |||||||||||||||||||||||||||
| 132 | 0 | (undef, $data{name}, undef, $tmp) = split(/\n/, $tmp); | |||||||||||||||||||||||||||
| 133 | 0 | ($data{account}, $data{currency}) = split(/\//, $tmp); | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | $data{account} = $self->_cleanup($data{account}); | |||||||||||||||||||||||||||
| 136 | 0 | $data{name} = $self->_cleanup($data{name}); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # get the balance and the final balance of the account. | ||||||||||||||||||||||||||||
| 139 | 0 | for(qw/balance final/) { | |||||||||||||||||||||||||||
| 140 | 0 | $stream->get_tag('table'); | |||||||||||||||||||||||||||
| 141 | 0 | $stream->get_tag('td') for 1 .. 2; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | $data{$_} = $stream->get_trimmed_text('/td'); | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | $data{$_} = $self->_scalar2float($data{$_}) if $self->return_floats; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | push @{$result{accounts}}, \%data; | |||||||||||||||||||||||||||
| 148 | # catch wertpapierdepots | ||||||||||||||||||||||||||||
| 149 | } elsif($type eq 'Wertpapierdepot') { | ||||||||||||||||||||||||||||
| 150 | # get name and number of the fund. | ||||||||||||||||||||||||||||
| 151 | 0 | $stream->get_tag('a'); | |||||||||||||||||||||||||||
| 152 | 0 | (undef, $data{name}, undef, $data{fund}) = split(/\n/, $stream->get_text('/a')); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | $data{fund} = $self->_cleanup($data{fund}); | |||||||||||||||||||||||||||
| 155 | 0 | $data{name} = $self->_cleanup($data{name}); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # get the balance of the fund. | ||||||||||||||||||||||||||||
| 158 | 0 | $stream->get_tag('table'); | |||||||||||||||||||||||||||
| 159 | 0 | $stream->get_tag('td'); | |||||||||||||||||||||||||||
| 160 | 0 | $data{currency} = $stream->get_trimmed_text('/td'); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | $stream->get_tag('td'); | |||||||||||||||||||||||||||
| 163 | 0 | $data{balance} = $stream->get_trimmed_text('/td'); | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | $data{balance} = $self->_scalar2float($data{balance}) if $self->return_floats; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | push @{$result{funds}}, \%data; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | \%result; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub _scalar2float { | ||||||||||||||||||||||||||
|
Subroutine
_scalar2float: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 176 | 0 | my($self, $scalar) = @_; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | $scalar =~ s/\.//g; | |||||||||||||||||||||||||||
| 179 | 0 | $scalar =~ s/,/\./g; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | return $scalar; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub _cleanup { | ||||||||||||||||||||||||||
|
Subroutine
_cleanup: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 186 | 0 | my($self, $string) = @_; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | $string =~ s/^\s+//g; | |||||||||||||||||||||||||||
| 189 | 0 | $string; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 1 | 1; | |||||||||||||||||||||||||||