Add note re: LibreOffice bug
[einar-bin] / zec.sh
1 #!/bin/bash
2 LC_NUMERIC="en_US.utf-8"
3 CacheFile="/tmp/coinindex.json"
4 CacheFile2="/tmp/usd-nok.csv"
5 ApiURL="https://www.worldcoinindex.com/apiservice/json?key=iOU8ko9QJ01Qj1JXoXfAXaoLD"
6 ApiURL2="https://data.norges-bank.no/api/data/EXR/B.NOK.USD.SP.A?lastNObservations=1&format=csv-:-tab-false-y"
7 CacheTime="150" # 150 seconds = 2.5 minutes
8 NumberRegex="^[0-9]+([.][0-9]+)?$"
9
10 if [ -z ${1+x} ]; then
11 Value=1
12 else
13 Value=${1}
14 fi
15
16 if ! [[ ${Value} =~ ${NumberRegex} ]]; then
17 echo "+++ OUT OF CHEESE ERROR +++"
18 exit 1
19 fi
20
21 if [ -f ${CacheFile} ]; then
22 if [ $(stat --format=%Y ${CacheFile}) -le $(( $(date +%s) - ${CacheTime} )) ]; then
23 wget -q -O ${CacheFile} ${ApiURL}
24 wget -q -O ${CacheFile2} ${ApiURL2}
25 fi
26 else
27 wget -q -O ${CacheFile} ${ApiURL}
28 wget -q -O ${CacheFile2} ${ApiURL2}
29 fi
30
31 PriceZECinUSD="$(jq '.Markets | .[] | select(.Name=="Zcash") | .Price_usd' ${CacheFile})"
32 PriceUSDinNOK="$(tail -n 1 ${CacheFile2} | cut -f 2 | tr -d \")"
33 PriceZECinNOK="$(echo "${PriceZECinUSD}*${PriceUSDinNOK}" | bc)"
34
35 ValueUSD="$(echo "${PriceZECinUSD}*${Value}" | bc | sed 's/^\./0./')"
36 ValueNOK="$(echo "${PriceZECinNOK}*${Value}" | bc | sed 's/^\./0./')"
37 ValueUSDPretty="$(printf "%0.4f\n" $ValueUSD)"
38 ValueNOKPretty="$(printf "%0.4f\n" $ValueNOK)"
39
40 echo "${Value} ZEC = \$ ${ValueUSDPretty} (about NOK ${ValueNOKPretty})"