2020-05-26 00:23:06 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Usage:
|
2021-08-18 12:35:04 +00:00
|
|
|
# price <url> <Name of currency> <icon> <Price to show in>
|
2020-05-26 00:23:06 +00:00
|
|
|
# price bat "Basic Attention Token" 🦁
|
|
|
|
# When the name of the currency is multi-word, put it in quotes.
|
|
|
|
|
|
|
|
[ -z "$3" ] && exit 1
|
2021-08-18 12:35:04 +00:00
|
|
|
|
|
|
|
# use $4 as currency, if not passed in use "usd" as default
|
|
|
|
currency="${4:-usd}"
|
2020-06-06 23:59:43 +00:00
|
|
|
interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
|
2020-05-26 00:23:06 +00:00
|
|
|
dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
|
2021-09-24 13:50:24 +00:00
|
|
|
pricefile="$dir/$1-$currency"
|
|
|
|
chartfile="$dir/$1-$currency-chart"
|
2020-05-26 00:23:06 +00:00
|
|
|
|
2021-09-24 13:50:24 +00:00
|
|
|
updateprice() { temp="$(mktemp)"
|
|
|
|
curl -s "$currency.rate.sx/1$1" > "$temp" &&
|
|
|
|
mv -f "$temp" "$pricefile" &&
|
|
|
|
curl -s "$currency.rate.sx/$1$interval" > "$temp" &&
|
|
|
|
mv -f "$temp" "$chartfile" ;}
|
2020-06-06 23:59:43 +00:00
|
|
|
|
2020-05-26 00:28:19 +00:00
|
|
|
[ -d "$dir" ] || mkdir -p "$dir"
|
|
|
|
|
2020-05-26 00:23:06 +00:00
|
|
|
[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] &&
|
2020-07-02 19:28:31 +00:00
|
|
|
updateprice "$1"
|
2020-05-26 00:23:06 +00:00
|
|
|
|
|
|
|
case $BLOCK_BUTTON in
|
2021-03-10 12:19:47 +00:00
|
|
|
1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
|
2020-07-02 19:28:31 +00:00
|
|
|
2) notify-send -u low "$3 Updating..." "Updating $2 price..."
|
2020-06-06 23:59:43 +00:00
|
|
|
updateprice "$1" && notify-send "$3 Update complete." "$2 price is now
|
|
|
|
\$$(cat "$pricefile")" ;;
|
2020-05-26 01:29:12 +00:00
|
|
|
3) uptime="$(date -d "$(stat -c %x "$pricefile")" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
|
|
|
|
notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
|
2020-05-26 00:23:06 +00:00
|
|
|
- Left click for chart of changes.
|
|
|
|
- Middle click to update.
|
|
|
|
- Shows 🔃 if updating prices.
|
|
|
|
- <b>Last updated:
|
|
|
|
$uptime</b>" ;;
|
|
|
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
|
|
|
esac
|
2020-06-06 23:59:43 +00:00
|
|
|
|
2021-09-24 13:50:24 +00:00
|
|
|
case "$currency" in
|
|
|
|
usd) symb="$" ;;
|
|
|
|
gbp) symb="£" ;;
|
|
|
|
eur) symb="€" ;;
|
|
|
|
btc) symb="₿" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
printf "$3$symb%0.2f$after" "$(cat "$pricefile")"
|