3 # Copyright © 2022 Nick Bowler
5 # Simple script to help convert the CSV dumps of daily exchange rates from
6 # the Bank of Canada into ledger price databases.
8 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
9 # This is free software: you are free to do what the fuck you want to.
10 # There is NO WARRANTY, to the extent permitted by law.
15 my ($file) = (@ARGV, "/dev/stdin");
16 my $csv = Text::CSV->new({ binary => 1 });
18 open my $fh, "<", $file or die "$file: $!";
21 last if /OBSERVATIONS/;
25 while (my $row = $csv->getline_hr($fh)) {
26 next unless $row->{date} =~ /....-..-../;
28 foreach (sort keys %$row) {
30 if ($fx =~ /^FX([[:upper:]]{3})CAD$/) {
31 print "P $row->{date} $1 $row->{$_} CAD\n"