#! /usr/bin/perl

use strict;
use warnings;

use Finance::Bank::Cahoot;

my $cahoot = Finance::Bank::Cahoot->new(
               credentials => 'ReadLine',
	       credentials_options => { account => '12345678',
					username => 'acmeuser' });
$cahoot->login;
my $accounts = $cahoot->accounts;

foreach my $account (@$accounts) {
  next unless $account->{name} =~ /current/;
  $cahoot->set_account($account->{account});
}

my $debits = $cahoot->debits;
foreach my $debit (@$debits) {
  print $debit->payee, q{,},
        $debit->reference, q{,},
        $debit->amount || 0, q{,},
        $debit->date || 0, q{,},
        $debit->frequency || 0, qq{\n};
}
