-
-
Save Altreus/b624700c3675449feedf22f5c7a64c52 to your computer and use it in GitHub Desktop.
doesn't like this NEXT phaser
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') || default-config; | |
my $xfers = $ofx.elements(:TAG('BANKTRANLIST'), :SINGLE, :RECURSE); | |
my $i = 0; | |
TXN: | |
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]; | |
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 TXN; | |
} | |
} | |
} | |
note "$i: No config matching $payee"; | |
NEXT { $i++ } | |
} | |
} | |
sub load-config (Str $file) { | |
use YAMLish; | |
my $io = $file.IO; | |
return unless $io.e; | |
load-yaml($io.slurp); | |
} | |
sub default-config { | |
{ | |
accounts => [], | |
matches => {}, | |
} | |
} | |
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 | |
2018-12-22 MARKS&SPENCER PLC # 1 | |
Budget:Groceries £-1234 | |
Test | |
labeled next without loop construct | |
in block at ofx2ledger line 36 | |
in sub MAIN at ofx2ledger line 13 | |
in block <unit> at ofx2ledger line 60 |
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