-
-
Save Altreus/09df5154ce5f5b304b7cd368bbf5dd74 to your computer and use it in GitHub Desktop.
weird loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matches: | |
- substr: waitrose | |
account: Budget:Groceries | |
- substr: marks&spencer | |
account: Budget:Groceries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#perl6 | |
use v6; | |
use XML; | |
sub MAIN ($xml-file, :$account) { | |
my $ofx = from-xml-file($xml-file); | |
my $conf = load-config('config.yaml'); | |
my $xfers = $ofx.elements(:TAG('BANKTRANLIST'), :SINGLE, :RECURSE); | |
my $i = 0; | |
for $xfers.elements(:TAG('STMTTRN')) -> $elem { | |
my $trntype = $elem.elements(:TAG('TRNTYPE'), :SINGLE)[0]; | |
next unless $trntype eq 'POS'; | |
my $dt = $elem.elements(:TAG('DTPOSTED'), :SINGLE)[0]; | |
$dt ~~ /(\d ** 4)(\d ** 2) ** 5/; | |
my $date = DateTime.new($/[0], |$/[1], | |
formatter => { sprintf "%d-%d-%d", .year, .month, .day given $^a } | |
); | |
my $payee = ~$elem.elements(:TAG('NAME') :SINGLE)[0]; | |
decode-elements($payee); | |
my $amt = $elem.elements(:TAG('TRNAMT') :SINGLE)[0]; | |
match: for $conf<matches><> -> $match { | |
if ($match<substr>) { | |
if $payee.Str.lc.index($match<substr>).defined { | |
say ($date, $payee, "# $i").join(' '); | |
say " $match<account> £$amt"; | |
say " $account"; | |
say ''; | |
next match; | |
} | |
} | |
note "$i: No config matching $payee"; | |
} | |
$i++; | |
} | |
} | |
sub load-config (Str $file) { | |
use YAMLish; | |
my $io = $file.IO; | |
return unless $io.e; | |
load-yaml($io.slurp); | |
} | |
sub decode-elements(Str $str is rw) { | |
$str ~~ s:g['&#x' (\d+)? ';'] = :16($/); | |
$str ~~ s:g/'&'/&/; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl6 ofx2ledger --account=Test test.ofx | |
0: No config matching MANOR FARM SHOP | |
0: No config matching MANOR FARM SHOP | |
1: No config matching MARKS&SPENCER PLC | |
2018-12-22 MARKS&SPENCER PLC # 1 | |
Budget:Groceries £-1234 | |
Test | |
2018-12-31 WAITROSE # 2 | |
Budget:Groceries £-1234 | |
Test | |
2: No config matching WAITROSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<?OFX OFXHEADER="200" VERSION="203" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?> | |
<OFX> | |
<BANKMSGSRSV1> | |
<STMTTRNRS> | |
<STMTRS> | |
<BANKTRANLIST> | |
<STMTTRN> | |
<TRNTYPE>POS</TRNTYPE> | |
<DTPOSTED>20181222120000.000[+0]</DTPOSTED> | |
<TRNAMT>-1234</TRNAMT> | |
<NAME>MANOR FARM SHOP</NAME> | |
</STMTTRN> | |
<STMTTRN> | |
<TRNTYPE>POS</TRNTYPE> | |
<DTPOSTED>20181222120000.000[+0]</DTPOSTED> | |
<TRNAMT>-1234</TRNAMT> | |
<NAME>MARKS&SPENCER PLC</NAME> | |
</STMTTRN> | |
<STMTTRN> | |
<TRNTYPE>POS</TRNTYPE> | |
<DTPOSTED>20181231120000.000[+0]</DTPOSTED> | |
<TRNAMT>-1234</TRNAMT> | |
<NAME>WAITROSE</NAME> | |
</STMTTRN> | |
</BANKTRANLIST> | |
</STMTRS> | |
</STMTTRNRS> | |
</BANKMSGSRSV1> | |
</OFX> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment