]> git.draconx.ca Git - scripts.git/blob - bocexchange-to-ledger.pl
Add script to convert "JWK"-format RSA keys to normal.
[scripts.git] / bocexchange-to-ledger.pl
1 #!/usr/bin/env perl
2 #
3 # Copyright © 2022 Nick Bowler
4 #
5 # Simple script to help convert the CSV dumps of daily exchange rates from
6 # the Bank of Canada into ledger price databases.
7 #
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.
11
12 use strict;
13 use Text::CSV;
14
15 my ($file) = (@ARGV, "/dev/stdin");
16 my $csv = Text::CSV->new({ binary => 1 });
17
18 open my $fh, "<", $file or die "$file: $!";
19
20 while (<$fh>) {
21         last if /OBSERVATIONS/;
22 }
23 $csv->header($fh);
24
25 while (my $row = $csv->getline_hr($fh)) {
26         next unless $row->{date} =~ /....-..-../;
27
28         foreach (sort keys %$row) {
29                 my $fx = uc $_;
30                 if ($fx =~ /^FX([[:upper:]]{3})CAD$/) {
31                         print "P $row->{date} $1 $row->{$_} CAD\n"
32                 }
33         }
34
35 }