marvvin

[archived] IRC bot
git clone https://hhvn.uk/marvvin
git clone git://hhvn.uk/marvvin
Log | Files | Refs | README | LICENSE

currency (525B)


      1 #!/bin/sh
      2 
      3 [ -z $1 ] && echo "usage: crypto <amount> <input currency> in <output currency>" && exit 1
      4 
      5 amount="$1"
      6 [ "$(echo "$amount" | tr -d '\n')" != "$(echo "$amount" | tr -dc 0-9)" ] && echo "not a number" && exit 1
      7 from="$2"
      8 [ -z $4 ] && to="$3" || to="$4"
      9 
     10 mult=$(curl -qs "https://min-api.cryptocompare.com/data/price?fsym=$from&tsyms=$to" | awk -F"[\"}{:]" '{print $5}')
     11 [ -z $mult ] && echo "invalid currencies" && exit 1
     12 
     13 echo "scale=15; $amount * $mult" | bc | tr -d '\n'
     14 echo " $to" | tr '[:lower:]' '[:upper:]'