summaryrefslogtreecommitdiffstats
path: root/statusbar/sb-price
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-09-24 12:21:56 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-09-24 12:21:56 +0530
commit86f99da8d08e1f2e290d8ebfd5adb016faff7bac (patch)
tree8f121a2aaa187d8266e20df23ad36262ab051866 /statusbar/sb-price
downloadbin-86f99da8d08e1f2e290d8ebfd5adb016faff7bac.tar.gz
bin-86f99da8d08e1f2e290d8ebfd5adb016faff7bac.tar.bz2
bin-86f99da8d08e1f2e290d8ebfd5adb016faff7bac.zip
script's
Diffstat (limited to 'statusbar/sb-price')
-rwxr-xr-xstatusbar/sb-price50
1 files changed, 50 insertions, 0 deletions
diff --git a/statusbar/sb-price b/statusbar/sb-price
new file mode 100755
index 0000000..42c84c1
--- /dev/null
+++ b/statusbar/sb-price
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# Usage:
+# price <url> <Name of currency> <icon> <Price to show in>
+# price bat "Basic Attention Token" 🦁
+# When the name of the currency is multi-word, put it in quotes.
+
+[ -z "$3" ] && exit 1
+
+# use $4 as currency, if not passed in use "usd" as default
+currency="${4:-usd}"
+interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
+dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
+pricefile="$dir/$1-$currency"
+chartfile="$dir/$1-$currency-chart"
+
+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" ;}
+
+[ -d "$dir" ] || mkdir -p "$dir"
+
+[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] &&
+ updateprice "$1"
+
+case $BLOCK_BUTTON in
+ 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
+ 2) notify-send -u low "$3 Updating..." "Updating $2 price..."
+ updateprice "$1" && notify-send "$3 Update complete." "$2 price is now
+\$$(cat "$pricefile")" ;;
+ 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>
+- 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
+
+case "$currency" in
+ usd) symb="$" ;;
+ gbp) symb="£" ;;
+ eur) symb="€" ;;
+ btc) symb="₿" ;;
+esac
+
+printf "$3$symb%0.2f$after" "$(cat "$pricefile")"