Finance-Bank-Wachovia

 view release on metacpan or  search on metacpan

scripts/wachovia_summary.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
};

# 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} ){
	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->{userid} && $opts->{password} ) ){
		print "Need either login info, or file-key to login.  see `perldoc wachovia.pl`\n";	
		exit(1);
	}	
}
my $x;

my %login_info = $opts->{userid}
	? ( user_id => $opts->{userid}, 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_nums = $wachovia->account_numbers();

die $wachovia->ErrStr()
	if $wachovia->ErrStr;

my($num, $name, $type, $bal) = qw/Number Name Type Balance/;
format Summary = 
@<<<<<<<<<<<<<<<<  @<<<<<<<<<<<<<<<<<<<<<<<<  @>>>>>>>>>>	  
$num,              $name, 		              $bal
.
$~ = 'Summary';
write;
print <<EOF;
=================  =========================  ===========
EOF

foreach $num ( @account_nums ){
	my $a = $wachovia->account( $num );
	$name = $a->name    or die $a->ErrStr;
	#$type = $a->type    or die $a->ErrStr;
	$bal  = $a->balance or die $a->ErrStr;
	write;
}



#==============================================================================  
# Fills the options hash with account info from the local .wachovia file
sub get_account_info {
	my($keyfile, $key) = @_;
	my $opts;
	return unless -e $keyfile;
	open( F, $keyfile ) or die "Can't open ".$keyfile." for reading: $!";



( run in 1.071 second using v1.01-cache-2.11-cpan-4ac696b4eb4 )