Created
July 28, 2022 01:32
-
-
Save keymon/6bbe957ec1314af682b342f44faf1631 to your computer and use it in GitHub Desktop.
Download HMRC monthly exchange rates and convert to JSON/CSV
This file contains hidden or 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
for i in 21 22; do for o in 0{1,2,3,4,5,6,7,8,9} 10 11 12; do wget http://www.hmrc.gov.uk/softwaredevelopers/rates/exrates-monthly-$o$i.XML; done; done | |
for i in *; do xq < $i; done | \ | |
jq ' | |
.exchangeRateMonthList | | |
(."@Period" | split(" ")[0] | strptime("%d/%b/%Y") | strftime("%d/%m/%Y")) as $from | | |
(."@Period" | split(" ")[2] | strptime("%d/%b/%Y") | strftime("%d/%m/%Y")) as $to | | |
.exchangeRate[] | | |
select(.currencyCode == "USD") | | |
{from: $from, to: $to, rate: .rateNew} | |
' | \ | |
jq -s '.' | \ | |
jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment