Finance-Bank-Wachovia
view release on metacpan or search on metacpan
scripts/wachovia.pl view on Meta::CPAN
#!/usr/bin/perl
use Finance::Bank::Wachovia;
use strict;
$| = 1;
our $VERSION = 0.4;
# set option defaults
my $opts = {
keyfile => $ENV{HOME}.'/.wachovia', # file that stores encrypted login info + account number
details => 10, # report type: balance|summary|details
};
# parse command line options -- see perldocs for info
for (@ARGV){
$opts->{lc($1)} = $2 if /--([\w-]+)=(.+)/g;
$opts->{lc($1)} = 1 if /^--([\w-]+)$/g;
}
# Since I can never remember myself which one of these it is, then
# why not make them all valid?
my $userid;
my $password;
$opts->{user_id} = $userid if( $userid = $opts->{userid}
|| $opts->{user_id}
|| $opts->{user}
|| $opts->{login}
|| $opts->{'user-id'}
|| $opts->{id}
|| $opts->{name}
);
$opts->{password} = $password if( $password = $opts->{password}
|| $opts->{pass}
|| $opts->{pw}
);
if( $opts->{key} ){
# indicates we are storing/retrieving data from keyfile
eval {
require Crypt::CBC;
import Crypt::CBC;
};
if($@){ die "Must have Crypt::CBC and Crypt::DES_PP module installed to use --key feature: $@\n" }
# if here, then user provided key + some info, so we want to preserve whatever it is they provided
# while keeping whatever it is they didn't provide.
my $new_opts = {};
my $file_opts = get_account_info( $opts->{keyfile}, $opts->{key} );
for(keys %$opts){ $new_opts->{$_} = $opts->{$_} }
for(keys %$file_opts){ $new_opts->{$_} = $file_opts->{$_} unless $new_opts->{$_} }
$opts = $new_opts;
save_account_info( $opts );
}
else{
# if here, then the user must provide all the info them self, and they don't plan on keeping it
# in a key-file.
unless( ( $opts->{can} && $opts->{pin} && $opts->{codeword} ) || ( $opts->{user_id} && $opts->{password} ) ){
print "Need either login info, or file-key to login. see `perldoc wachovia.pl`\n";
exit(1);
}
}
my $x;
die "Must provide account number, see perldocs for $0 to learn more."
unless $opts->{account};
my %login_info = $opts->{user_id}
? ( user_id => $opts->{user_id}, password => $opts->{password} )
: ( customer_access_number => $opts->{can}, pin => $opts->{pin}, code_word => $opts->{codeword} );
my $wachovia = Finance::Bank::Wachovia->new( %login_info )
or die Finance::Bank::Wachovia->ErrStr;
my $account = $wachovia->account( $opts->{account} )
or die $wachovia->ErrStr;
print $account->available_balance, "\n" and exit if $opts->{balance};
print "Acct Number: ", $account->number, "\n";
print "Acct Name : ", $account->name, ($opts->{details}?" ( ".$account->type." )":''), "\n";
print "Avail. Bal.: ", $account->available_balance, "\n";
exit unless $opts->{details};
print "Posted.Bal.: ", $account->posted_balance, "\n";
my $transactions = $account->transactions
or die $account->ErrStr;
my($date, $desc, $with, $deposit, $bal) = qw/Date Description Withdrawal Deposit Balance/;
format Transactions =
@<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>>
$date, $desc, $with, $deposit, $bal
.
$~ = 'Transactions';
write;
print <<EOF;
===== ================================================= =========== =========== ===========
EOF
my $end = @$transactions < $opts->{details} ? $#{$transactions} : $opts->{details};
$end = $#{$transactions} if $end eq 'all';
foreach my $t ( (reverse @$transactions)[0..$end] ){
$date = substr $t->date, 0, 5;
$desc = $t->description;
$with = $t->withdrawal_amount ? $t->withdrawal_amount : '';
$deposit = $t->deposit_amount ? $t->deposit_amount : '';
( run in 1.150 second using v1.01-cache-2.11-cpan-df04353d9ac )