summaryrefslogtreecommitdiffstats
path: root/.local/bin/statusbar/sb-forecast
diff options
context:
space:
mode:
authorappeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com>2026-06-30 03:52:33 +0000
committerGitHub <noreply@github.com>2026-06-29 23:52:33 -0400
commit0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66 (patch)
tree4ab852fa1a3d8e0c79e85e345b88ed6333a5c155 /.local/bin/statusbar/sb-forecast
parentf82018293b3619485787075023ab4e9af2fd0f58 (diff)
downloadeibhear-0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66.tar.gz
eibhear-0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66.tar.zst
eibhear-0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66.zip
Make dwmblocks modules async (#1296)
* Make dwmblocks modules async * Allow dwmblocks signal numbers to be changed * Become synchronous on manual run and make dwmblocks signal code optional * Merge latest commits and add retries * Re-add fail-early to sb-price * Make the retry logic better + other changes * Only redirect non-empty output: for when services are down * Also change modification time * Robustness not needed anymore because of curl's --output, no more empty files * Use actual locks instead of pgrep * Change to more suitable lock file location for user programs * Implement thetubster's changes (fast retry and bug fixes)
Diffstat (limited to '.local/bin/statusbar/sb-forecast')
-rwxr-xr-x.local/bin/statusbar/sb-forecast22
1 files changed, 17 insertions, 5 deletions
diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast
index 5225601..645e7a2 100755
--- a/.local/bin/statusbar/sb-forecast
+++ b/.local/bin/statusbar/sb-forecast
@@ -7,11 +7,13 @@ url="${WTTRURL:-wttr.in}"
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
# Get a weather report from 'wttr.in' and save it locally.
-getforecast() { timeout --signal=1 2s curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; }
+getforecast() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
+ curl -sf "$url/$LOCATION" --output "$weatherreport" && touch "$weatherreport"
+}
# Forecast should be updated only once a day.
checkforecast() {
- [ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null |
+ [ "$(stat -c %y "$weatherreport" 2>/dev/null |
cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
}
@@ -34,6 +36,7 @@ readfile() { weatherdata="$(cat "$weatherreport")" ;}
showweather() {
readfile
+ # shellcheck disable=SC2046,SC2183
printf "☔%s 🥶%s° 🌞%s°\n" "$(getprecipchance)" $(getdailyhighlow)
}
@@ -48,6 +51,15 @@ case $BLOCK_BUTTON in
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
-checkforecast || getforecast
-
-showweather
+# shellcheck disable=SC2015
+checkforecast && showweather ||
+ ( flock -n 9 &&
+ ( tries=0; while [ $tries -ne 100 ]; do
+ getforecast && break ||
+ { tries=$((tries+1)); sleep .1; }
+ done
+ ! checkforecast &&
+ until getforecast; do sleep 60; done
+ pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}"
+ ) &
+ echo ) 9>"${XDG_RUNTIME_DIR}/sb-forecast.lock"