summaryrefslogtreecommitdiff
path: root/ar/.local/bin/statusbar
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-05-27 11:45:29 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-05-27 11:45:29 +0900
commit0ad8f5becf6a92fb54ada9d42beb4cb55082da1c (patch)
tree4335625b424475fd180b7aaac89125e4b3af623c /ar/.local/bin/statusbar
parente43e5f40adfcf147bb3ecdea33e9163fc585562f (diff)
modified statusbar/sb-forecast
Diffstat (limited to 'ar/.local/bin/statusbar')
-rwxr-xr-xar/.local/bin/statusbar/sb-forecast9
1 files changed, 8 insertions, 1 deletions
diff --git a/ar/.local/bin/statusbar/sb-forecast b/ar/.local/bin/statusbar/sb-forecast
index 5b58e53..16e2357 100755
--- a/ar/.local/bin/statusbar/sb-forecast
+++ b/ar/.local/bin/statusbar/sb-forecast
@@ -24,6 +24,9 @@ fi
weatherreport="${XDG_CACHE_HOME:-${HOME}/.cache}/weatherreport"
weatherreportjson="${XDG_CACHE_HOME:-${HOME}/.cache}/weatherreport.json"
+# Records the lat,lon the current report was fetched for, so the forecast is
+# refreshed immediately when the location changes (not just every 3 hours).
+weatherreportloc="${XDG_CACHE_HOME:-${HOME}/.cache}/weatherreport.loc"
error() {
rm -f "$weatherreport" "$weatherreportjson"
@@ -40,6 +43,7 @@ getweatherreportjson() {
"https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&hourly=temperature_2m,apparent_temperature,relative_humidity_2m,precipitation_probability,snowfall,wind_speed_10m,weather_code&daily=temperature_2m_min,temperature_2m_max,precipitation_probability_max&timezone=auto&wind_speed_unit=kmh&forecast_days=1") || error "reportjson"
echo "$tmp" | jq -e '.hourly' >/dev/null 2>&1 || error "reportjson"
echo "$tmp" >"$weatherreportjson"
+ echo "$location" >"$weatherreportloc"
}
# Fetch a text weather report from wttr.in and save it locally.
@@ -443,5 +447,8 @@ After $secs seconds, new clicks will also automatically update the doppler RADAR
8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
-checkforecast "$weatherreportjson" "10800" || { getweatherreportjson && getweatherreport && pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" && sleep 3; }
+# Refresh if the cached forecast is stale (>3h) or was fetched for a different location.
+if ! checkforecast "$weatherreportjson" "10800" || { [ -n "$location" ] && [ "$(cat "$weatherreportloc" 2>/dev/null)" != "$location" ]; }; then
+ getweatherreportjson && getweatherreport && pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" && sleep 3
+fi
showweather