| 1 | # $Id: Bundesschatz.pm,v 1.3 2003/10/12 12:03:43 florian Exp $ | ||||||||||
| 2 | |||||||||||
| 3 | package Finance::Bank::Bundesschatz; | ||||||||||
| 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://www.bundesschatz.at/ebss/kunde/pages/Logon.jsp', | |||||||||
| 14 | 1 | }; | |||||||||
| 15 | use Class::MethodMaker | ||||||||||
| 16 | 1 | ▶ | new_hash_init => 'new', | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | get_set => [ qw/account pass coowner _agent/ ], | ||||||||||
| 18 | 1 | boolean => [ qw/return_floats _connected/ ]; | |||||||||
| 19 | |||||||||||
| 20 | 1 | our $VERSION = '1.01'; | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | # login into the online banking system. | ||||||||||
| 24 | # fail if either account or password isn't defined. | ||||||||||
| 25 | # | ||||||||||
| 26 | # XXX: catch login errors. | ||||||||||
| 27 | 0 | ▶ | sub _connect { | ||||||||
|
Subroutine
_connect: not called CC=5 SCAR=34.0
| |||||||||||
| 28 | 0 | my $self = shift; | |||||||||
| 29 | 0 | my $content; | |||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | croak "Need account to connect.\n" unless $self->account; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | ▶ | croak "Need password to connect.\n" unless $self->pass; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | 0 | $self->_agent(WWW::Mechanize->new); | |||||||||
| 35 | 0 | $self->_agent->agent_alias('Mac Safari'); | |||||||||
| 36 | 0 | $self->_agent->get(LOGIN_URL); | |||||||||
| 37 | 0 | $self->_agent->form_number(1); | |||||||||
| 38 | 0 | $self->_agent->field('logon_user', $self->account); | |||||||||
| 39 | 0 | $self->_agent->field('logon_bnr', $self->coowner); | |||||||||
| 40 | 0 | $self->_agent->field('logon_passwd', $self->pass); | |||||||||
| 41 | 0 | $self->_agent->click('button_ok'); | |||||||||
| 42 | |||||||||||
| 43 | 0 | $content = $self->_agent->content; | |||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | croak "The online banking system told me, that the account or the password was invalid.\n" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | if $content =~ /Fehler: Bitte überprüfen Sie Ihre Kontonummer und Ihr Passwort/; | ||||||||||
| 47 | |||||||||||
| 48 | # fail on everything which doesn't look like the Kontostand page. | ||||||||||
| 49 | 0 | ▶ | croak "It seems as if the online banking system want's your attention.\n" . | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | "Please login manually and take a look.\n" | ||||||||||
| 51 | if $content !~ /Kontostand von:/; | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | # fetches and parses the summary page. | ||||||||||
| 56 | # | ||||||||||
| 57 | # returns a hashref containing the isolated data. | ||||||||||
| 58 | 0 | ▶ | sub check_balance { | ||||||||
|
Subroutine
check_balance: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 59 | 0 | my $self = shift; | |||||||||
| 60 | 0 | my $stream; | |||||||||
| 61 | my %data; | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | defined $self->_agent or $self->_connect; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | 0 | $self->_agent->follow_link(url_regex => qr/Kontostand/); | |||||||||
| 66 | 0 | $stream = HTML::TokeParser->new(\($self->_agent->content)); | |||||||||
| 67 | |||||||||||
| 68 | 0 | $stream->get_tag('form'); | |||||||||
| 69 | 0 | $stream->get_tag('tr') for 1 .. 5; | |||||||||
| 70 | 0 | $stream->get_tag('td') for 1 .. 5; | |||||||||
| 71 | 0 | $data{balance} = $stream->get_trimmed_text('/td'); | |||||||||
| 72 | |||||||||||
| 73 | 0 | $stream->get_tag('tr') for 1 .. 2; | |||||||||
| 74 | 0 | $stream->get_tag('td') for 1 .. 5; | |||||||||
| 75 | 0 | $data{interest} = $stream->get_trimmed_text('/td'); | |||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | if($self->return_floats) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | $data{$_} = $self->_scalar2float($data{$_}) | ||||||||||
| 79 | 0 | for qw/balance interest/; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 0 | \%data; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | # fetches and parses the detail page. | ||||||||||
| 87 | # | ||||||||||
| 88 | # returns a arrayref containing all entries. | ||||||||||
| 89 | 0 | ▶ | sub get_details { | ||||||||
|
Subroutine
get_details: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||
| 90 | 0 | my $self = shift; | |||||||||
| 91 | 0 | my $stream; | |||||||||
| 92 | my @entries; | ||||||||||
| 93 | 0 | my $content; | |||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | defined $self->_agent or $self->_connect; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | |||||||||||
| 97 | 0 | $self->_agent->follow_link(url_regex => qr/Kontodetails/); | |||||||||
| 98 | 0 | $content = $self->_agent->content; | |||||||||
| 99 | 0 | $content =~ /<!-- Data Rows -->(.*)<!-- Summen -->/s; | |||||||||
| 100 | 0 | $stream = HTML::TokeParser->new(\$1); | |||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | while ($stream->get_tag('tr')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | my %data; | |||||||||
| 104 | |||||||||||
| 105 | 0 | $stream->get_tag('td') for 1 .. 5; | |||||||||
| 106 | 0 | $data{product} = $stream->get_trimmed_text('/td'); | |||||||||
| 107 | |||||||||||
| 108 | 0 | $stream->get_tag('td') for 1 .. 2; | |||||||||
| 109 | 0 | ($data{from}, $data{to}) = | |||||||||
| 110 | split / - /, $stream->get_trimmed_text('/td'); | ||||||||||
| 111 | |||||||||||
| 112 | 0 | for(qw/currency amount interest interest_amount | |||||||||
| 113 | tax amount_after_tax/) { | ||||||||||
| 114 | 0 | $stream->get_tag('td') for 1 .. 2; | |||||||||
| 115 | 0 | $data{$_} = $stream->get_trimmed_text('/td'); | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 0 | ▶ | if($self->return_floats) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | $data{$_} = $self->_scalar2float($data{$_}) | ||||||||||
| 120 | 0 | for qw/amount interest interest_amount | |||||||||
| 121 | tax amount_after_tax/; | ||||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 0 | $stream->get_tag('/tr') for 1 .. 2; | |||||||||
| 125 | |||||||||||
| 126 | 0 | push @entries, \%data; | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | 0 | \@entries; | |||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | |||||||||||
| 133 | 0 | ▶ | sub check_interest { | ||||||||
|
Subroutine
check_interest: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||
| 134 | 0 | my $self = shift; | |||||||||
| 135 | 0 | my @entries; | |||||||||
| 136 | my $stream; | ||||||||||
| 137 | |||||||||||
| 138 | 0 | ▶ | defined $self->_agent or $self->_connect; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | |||||||||||
| 140 | 0 | $self->_agent->follow_link(url_regex => qr/Zinschart/); | |||||||||
| 141 | 0 | $self->_agent->follow_link(url_regex => qr/Zinsentwicklung/); | |||||||||
| 142 | |||||||||||
| 143 | 0 | $stream = HTML::TokeParser->new(\($self->_agent->content)); | |||||||||
| 144 | |||||||||||
| 145 | 0 | $stream->get_tag('/form'); | |||||||||
| 146 | 0 | $stream->get_tag('table') for 1 .. 2; | |||||||||
| 147 | 0 | $stream->get_tag('tr') for 1 .. 3; | |||||||||
| 148 | |||||||||||
| 149 | 0 | while (1) { | |||||||||
| 150 | 0 | my %data; | |||||||||
| 151 | |||||||||||
| 152 | 0 | ▶ | last unless $stream->get_tag('tr'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 153 | |||||||||||
| 154 | 0 | $stream->get_tag('td') for 1 .. 3; | |||||||||
| 155 | 0 | $data{published} = $stream->get_trimmed_text('/td'); | |||||||||
| 156 | 0 | $stream->get_tag('td') for 1 .. 4; | |||||||||
| 157 | 0 | $data{valid_on} = $stream->get_trimmed_text('/td'); | |||||||||
| 158 | 0 | $stream->get_tag('td') for 1 .. 4; | |||||||||
| 159 | 0 | $data{interest_bs1} = $stream->get_trimmed_text('/td'); | |||||||||
| 160 | 0 | $stream->get_tag('td') for 1 .. 4; | |||||||||
| 161 | 0 | $data{interest_bs2} = $stream->get_trimmed_text('/td'); | |||||||||
| 162 | 0 | $stream->get_tag('td') for 1 .. 4; | |||||||||
| 163 | 0 | $data{interest_bs3} = $stream->get_trimmed_text('/td'); | |||||||||
| 164 | |||||||||||
| 165 | 0 | ▶ | if($self->return_floats) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 166 | $data{$_} = $self->_scalar2float($data{$_}) | ||||||||||
| 167 | 0 | for qw/interest_bs1 interest_bs2 interest_bs3/; | |||||||||
| 168 | } | ||||||||||
| 169 | |||||||||||
| 170 | 0 | push @entries, \%data; | |||||||||
| 171 | } | ||||||||||
| 172 | |||||||||||
| 173 | # remove the last element of the entries list because it's always | ||||||||||
| 174 | # empty. well, kind of ugly, but i couldn't find another way. | ||||||||||
| 175 | 0 | pop @entries; | |||||||||
| 176 | |||||||||||
| 177 | 0 | \@entries; | |||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | |||||||||||
| 181 | # converts given scalar ($scalar) into a float and returns it. | ||||||||||
| 182 | 0 | ▶ | sub _scalar2float { | ||||||||
|
Subroutine
_scalar2float: not called CC=2 SCAR=17.9
| |||||||||||
| 183 | 0 | my($self, $scalar) = @_; | |||||||||
| 184 | |||||||||||
| 185 | 0 | ▶ | defined $scalar or return undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 186 | |||||||||||
| 187 | 0 | $scalar =~ s/[\.%]//g; | |||||||||
| 188 | 0 | $scalar =~ s/,/\./g; | |||||||||
| 189 | |||||||||||
| 190 | 0 | $scalar; | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | |||||||||||
| 194 | 1 | 1; | |||||||||