commit c3b0494a83d0904ef58fc5e75dac5f262ae84d63 parent 189e465995beebdf81f9efe402b71855fd6c8a78 Author: hhvn <hayden@haydenvh.com> Date: Mon, 15 Feb 2021 20:22:08 +0000 .scripts/bin/crypto .scripts/bin/currency: the crypto api can also deal with fiat, replace/symlink Diffstat:
T | .scripts/bin/crypto | | | 0 | |
M | .scripts/bin/currency | | | 10 | +++++----- |
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/.scripts/bin/crypto b/.scripts/bin/crypto diff --git a/.scripts/bin/currency b/.scripts/bin/currency @@ -1,10 +1,10 @@ #!/bin/sh -[ -z $1 ] && echo "usage: currency <amount> <input currency> in <output currency>" +[ -z $1 ] && echo "usage: $(basename $0) <amount> <input currency> in <output currency>" && exit -table=$(curl -qs https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml) +from="$2" +to="$4" -inputrate=$(echo "$table" | grep -oi "<Cube currency=\"$2\"[^>]*" | head -n 1 | awk -F\" '{print $4}') -outputrate=$(echo "$table" | grep -oi "<Cube currency=\"$4\"[^>]*" | head -n 1 | awk -F\" '{print $4}') +mult=$(curl -qs "https://min-api.cryptocompare.com/data/price?fsym=$from&tsyms=$to" | awk -F"[\"}{:]" '{print $5}') -echo "scale=5; $1 / $inputrate * $outputrate" | bc +echo "scale=15; $1 * $mult" | bc