added more advance weather capabilities

This commit is contained in:
2026-09-13 00:25:32 -06:00
parent dabda20dae
commit dd7868e732
4 changed files with 42 additions and 19 deletions
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Open the hourly weather forecast (wttr.in v2 view) in a ghostty window;
# focus it if it is already open. Intended as the on-click action for the
# waybar weather module.
set -uo pipefail
if hyprctl clients -j 2>/dev/null | jq -e 'any(.[]; ((.title // "") + " " + (.class // "")) | ascii_downcase | contains("wttr"))' >/dev/null 2>&1; then
hyprctl dispatch 'hl.dsp.focus({ window = "title:wttr" })' 2>/dev/null || true
exit 0
fi
CITY="${WEATHER_CITY:-Denver}"
ghostty --title=wttr -e bash -c 'curl -fsS --max-time 15 "https://v2.wttr.in/'"${CITY}"'"; printf "\n"; read -r -p "Press Enter to close"' &
disown
+23 -16
View File
@@ -1,17 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Print the current weather as a short icon+temp string, e.g. "🌦️ +83°F". # Print the current weather as a short icon+temp string, e.g. "🌦️ +83°F",
# Caches the wttr.in response so the lock screen and waybar don't hit the # plus -- in --json mode (for waybar) a multi-line "current conditions"
# network on every refresh. A cached value is served immediately -- even when # tooltip. A single cached wttr.in response is served immediately -- even when
# stale -- and refreshed in the background, so a slow network never delays the # stale -- and refreshed in the background, so a slow network never delays the
# lock screen's first frame. Override the location with WEATHER_CITY or edit # lock screen's first frame or waybar's tooltip. Override the location with
# CITY below. # WEATHER_CITY or edit CITY below.
set -u set -u
CITY="${WEATHER_CITY:-Denver}" CITY="${WEATHER_CITY:-Denver}"
CACHE_DIR="${XDG_RUNTIME_DIR:-/tmp}" CACHE_DIR="${XDG_RUNTIME_DIR:-/tmp}"
CACHE="${CACHE_DIR}/wttr.cache" CACHE="${CACHE_DIR}/wttr.cache"
CACHE_MAX_AGE=1800 # 30 minutes CACHE_MAX_AGE=1800 # 30 minutes
URL="https://wttr.in/${CITY}?format=%c+%t" # First line is the waybar text; the following lines are the hover tooltip.
FORMAT='%c+%t%5Cn%5Cn%C%5CnTemperature:+%t+%28feels+like+%f%29%5CnHumidity:+%h%5CnWind:+%w%5CnPrecipitation:+%p%5CnPressure:+%P%5CnUV+index:+%u'
URL="https://wttr.in/${CITY}?format=${FORMAT}"
fetch() { fetch() {
TMP="${CACHE}.tmp.$$" TMP="${CACHE}.tmp.$$"
@@ -24,25 +26,30 @@ fetch() {
fi fi
} }
# Fresh cache: print it. # Fresh cache: use it as-is.
if [ -f "${CACHE}" ] && [ "$(( $(date +%s) - $(stat -c %Y "${CACHE}") ))" -lt "${CACHE_MAX_AGE}" ]; then if [ -f "${CACHE}" ] && [ "$(( $(date +%s) - $(stat -c %Y "${CACHE}") ))" -lt "${CACHE_MAX_AGE}" ]; then
cat "${CACHE}" BODY="$(cat "${CACHE}")"
exit 0 # Stale cache: use it immediately, then refresh in the background so the
fi
# Stale cache: print it immediately, then refresh in the background so the
# caller never blocks. flock keeps a pile-up of refreshes from several clients # caller never blocks. flock keeps a pile-up of refreshes from several clients
# (lock screen, waybar) from running concurrent curls. # (lock screen, waybar) from running concurrent curls.
if [ -f "${CACHE}" ]; then elif [ -f "${CACHE}" ]; then
cat "${CACHE}" BODY="$(cat "${CACHE}")"
( (
exec 9>"${CACHE}.lock" exec 9>"${CACHE}.lock"
flock -n 9 || exit 0 flock -n 9 || exit 0
fetch >/dev/null 2>&1 fetch >/dev/null 2>&1
) & ) &
disown disown
# No cache at all: fetch synchronously, but with tight timeouts.
else
BODY="$(fetch)"
fi
if [ "${1:-text}" = "--json" ]; then
TEXT="$(printf '%s' "${BODY}" | head -n 1)"
TOOLTIP="$(printf '%s' "${BODY}" | tail -n +2)"
jq -nc --arg text "${TEXT}" --arg tip "${TOOLTIP}" '{text: $text, tooltip: $tip}'
exit 0 exit 0
fi fi
# No cache at all: fetch synchronously, but with tight timeouts. printf '%s' "${BODY}" | head -n 1
fetch
+1 -1
View File
@@ -56,5 +56,5 @@
} }
], ],
"workspace_rules": [], "workspace_rules": [],
"last_applied_time": 1789241254.0499482 "last_applied_time": 1789279298.6281931
} }
+4 -2
View File
@@ -30,9 +30,11 @@
}, },
"custom/weather": { "custom/weather": {
"format": "{}", "format": "{}",
"exec": "~/.local/bin/weather.sh", "exec": "~/.local/bin/weather.sh --json",
"return-type": "json",
"interval": 600, "interval": 600,
"tooltip": false "tooltip": true,
"on-click": "~/.local/bin/weather-forecast.sh"
}, },
"tray": { "tray": {
"icon-size": 16, "icon-size": 16,