3 ms·
In my case it is not Bash, but POSIX shell: #!/bin/sh set -eu u=https://www.ecb.europa.eu/stats/eurofxref/eurofxref.zip ftp -Vo - $u
by ninjin 3y ago
In my case it is not Bash, but POSIX shell:
#!/bin/sh
set -eu
u=https://www.ecb.europa.eu/stats/eurofxref/eurofxref.zip
ftp -Vo - $u | zcat | sed 's/, $//' | awk -F ', ' '
NR == 1 {
for(i = 1; i <= NF; ++i) {
col[$i] = i
c = ($i != "GBP") ? $i : "EUR"
printf "%s%s", c, (i < NF) ? "\t" : "\n"
}
}
NR >= 2 {
printf "%s\t", $1
for(i = 2; i <= NF; ++i) {
c = (i != col["GBP"]) ? $i/$(col["GBP"]) : $i
printf "%s%s", c, (i < NF) ? "\t" : "\n"
}
}
'
Fetches the latest rates and converts the base currency to GBP and format to TSV. Then I run a cron(8) job 15~30 minutes after the release each work day and dump the output so that I can retrieve it from httpd(8) over HTTPS to be injected into my window manager status bar. A pretty elegant solution that spares the ECB from my desktops hammering their server. All with tools from the OpenBSD base install.