efficiency and fail tweaks

This commit is contained in:
Luke Smith 2023-03-31 09:44:59 -04:00
parent 749f74f84e
commit 5a6c56d565
No known key found for this signature in database
GPG key ID: 4C50B54A911F6252

View file

@ -18,17 +18,15 @@ filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
[ -d "$dir" ] || mkdir -p "$dir" [ -d "$dir" ] || mkdir -p "$dir"
updateprice() { curl -sf -m 3 $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" || updateprice() { curl -sf -m 1 --fail-early $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" ||
rm -f "$pricefile" "$chartfile" ;} rm -f "$pricefile" "$chartfile" ;}
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && [ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
updateprice "$1" updateme="1"
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
2) notify-send -u low "$3 Updating..." "Updating $2 price..." 2) notify-send -u low "$3 Updating..." "Updating $2 price..." ; updateme="1" ; showupdate="1" ;;
updateprice "$1" && notify-send "$3 Update complete." "$2 price is now
\$$(cat "$pricefile")" ;;
3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")" 3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b> notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
- Left click for chart of changes. - Left click for chart of changes.
@ -39,6 +37,12 @@ case $BLOCK_BUTTON in
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac esac
[ -n "$updateme" ] &&
updateprice "$1" &&
[ -n "$showupdate" ] &&
notify-send "$3 Update complete." "$2 price is now
\$$(cat "$pricefile")"
case "$currency" in case "$currency" in
usd) symb="$" ;; usd) symb="$" ;;
gbp) symb="£" ;; gbp) symb="£" ;;