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]+)?$"
10 if [ -z ${1+x} ]; then
16 if ! [[ ${Value} =~
${NumberRegex} ]]; then
17 echo "+++ OUT OF CHEESE ERROR +++"
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}
27 wget
-q -O ${CacheFile} ${ApiURL}
28 wget
-q -O ${CacheFile2} ${ApiURL2}
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)"
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)"
40 echo "${Value} ZEC = \$ ${ValueUSDPretty} (about NOK ${ValueNOKPretty})"