1 #!/bin/sh 2 3 # Usage: 4 # price <url> <Name of currency> <icon> 5 # price bat "Basic Attention Token" 🦁 6 # When the name of the currency is multi-word, put it in quotes. 7 8 [ -z "$3" ] && exit 1 9 interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) 10 dir="$HOME/.local/share/crypto-prices" 11 pricefile="$dir/$1" 12 # chartfile="$dir/$1-chart" 13 14 # curl -s "rate.sx/1$1" > "$pricefile" 15 16 #updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 && 17 # curl -s "rate.sx/1$1" > "$pricefile" && 18 # curl -s "rate.sx/$1$interval" > "$chartfile" ;} 19 20 updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 && 21 price=$(binance-cli --keyfile ~/.local/go/bin/keys.json list-price --symbol $1 | grep price | awk {'print $2'} | sed 's/"//g') && 22 [ $(echo "$price == 0" | bc) -ne 1 ] && 23 echo $price > "$pricefile" ;} 24 25 [ -d "$dir" ] || mkdir -p "$dir" 26 27 # [ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && 28 # updateprice "$1" 29 updateprice "$1" & 30 31 # case $BLOCK_BUTTON in 32 # 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; 33 # 2) notify-send -u low "$3 Updating..." "Updating $2 price..." 34 # updateprice "$1" && notify-send "$3 Update complete." "$2 price is now 35 # \$$(cat "$pricefile")" ;; 36 # 3) uptime="$(date -d "$(stat -c %x "$pricefile")" '+%D at %T' | sed "s|$(date '+%D')|Today|")" 37 # notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b> 38 # - Left click for chart of changes. 39 # - Middle click to update. 40 # - Shows 🔃 if updating prices. 41 # - <b>Last updated: 42 # $uptime</b>" ;; 43 # 6) "$TERMINAL" -e "$EDITOR" "$0" ;; 44 # esac 45 46 printf "$3$%0.2f" "$(cat "$pricefile")"