From 028e0a4009347d4a4f4aa55b6e525c151a307b5d Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Fri, 4 Jun 2021 15:41:15 -0700 Subject: added scripts for dwmblocks --- statusbar/sb-price | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 statusbar/sb-price (limited to 'statusbar/sb-price') diff --git a/statusbar/sb-price b/statusbar/sb-price new file mode 100755 index 0000000..35b072f --- /dev/null +++ b/statusbar/sb-price @@ -0,0 +1,38 @@ +#!/bin/sh + +# Usage: +# price +# price bat "Basic Attention Token" 🦁 +# When the name of the currency is multi-word, put it in quotes. + +[ -z "$3" ] && exit 1 +interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) +dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices" +pricefile="$dir/$1" +chartfile="$dir/$1-chart" + +updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 && + curl -s "rate.sx/1$1" > "$pricefile" && + curl -s "rate.sx/$1$interval" > "$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" "\- Exact price: \$$(cat "$pricefile") +- Left click for chart of changes. +- Middle click to update. +- Shows 🔃 if updating prices. +- Last updated: + $uptime" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +printf "$3$%0.2f" "$(cat "$pricefile")" -- cgit v1.2.3-13-gbd6f