From fd964d54b6bfaab35304543c61cf2209e4fa1430 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Mon, 20 Mar 2023 09:50:18 -0400 Subject: [PATCH] customizable wttr/rate urls, sb-price improvements --- .config/shell/profile | 4 ++++ .local/bin/statusbar/sb-forecast | 3 ++- .local/bin/statusbar/sb-price | 21 ++++++++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.config/shell/profile b/.config/shell/profile index 26f8241..e78f21e 100644 --- a/.config/shell/profile +++ b/.config/shell/profile @@ -16,6 +16,10 @@ export TERMINAL="st" export TERMINAL_PROG="st" export BROWSER="librewolf" +# Change the default crypto/weather monitor sites. +# export CRYPTOURL="rate.sx" +# export WTTRURL="wttr.in" + # ~/ Clean-up: export XDG_CONFIG_HOME="$HOME/.config" export XDG_DATA_HOME="$HOME/.local/share" diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 2a6440b..2b41b3d 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -3,10 +3,11 @@ # Displays today's precipication chance (☔), and daily low (🥶) and high (🌞). # Usually intended for the statusbar. +url="${WTTRURL:-wttr.in}" weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" # Get a weather report from 'wttr.in' and save it locally. -getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1; } +getforecast() { curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; } # Forecast should be updated only once a day. checkforecast() { diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 42c84c1..53c5023 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -8,21 +8,20 @@ [ -z "$3" ] && exit 1 # use $4 as currency, if not passed in use "usd" as default +url="${CRYPTOURL:-rate.sx}" currency="${4:-usd}" interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) -dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices" +dir="${XDG_CACHE_HOME:-$HOME/.cache}/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" ;} +filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" -[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && +updateprice() { curl -sf -m 3 $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" || + rm -f "$pricefile" "$chartfile" ;} + +[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && updateprice "$1" case $BLOCK_BUTTON in @@ -30,7 +29,7 @@ case $BLOCK_BUTTON in 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|")" + 3) uptime="$(date -d "$filestat" '+%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. @@ -44,7 +43,7 @@ case "$currency" in usd) symb="$" ;; gbp) symb="£" ;; eur) symb="€" ;; - btc) symb="₿" ;; + btc) symb="" ;; esac -printf "$3$symb%0.2f$after" "$(cat "$pricefile")" +[ -f "$pricefile" ] && printf "$3$symb%0.2f" "$(cat "$pricefile")"