From 9cb98bef22f25e7576278ac965efa4259e2790fc Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sun, 11 Oct 2026 22:53:26 +0200 Subject: [PATCH] Handle stale data in ens-forecast brief in xmobar --- .config/xmobar/ens_brief.sh | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/.config/xmobar/ens_brief.sh b/.config/xmobar/ens_brief.sh index e3415f2..f0850c7 100755 --- a/.config/xmobar/ens_brief.sh +++ b/.config/xmobar/ens_brief.sh @@ -1,9 +1,38 @@ #!/bin/bash # Next day from ens-forecast for xmobar, e.g. "Sat 19/10° 39%" (today before 18:00, then tomorrow) # With "week": show the next 7 days in a notification (for a click on the bar) +# Uses IFS unless its newest saved run is STALE; then the first fallback in MODELS whose download names its +# run and isn't STALE. The bar names the model when it isn't IFS, and adds a red "!" when it is stale. +# AIFS/AIGEFS are left out: AIFS comes through the same ECMWF pipeline as IFS and fails with it. + +MODELS=(ecmwf_ifs025 ncep_gefs025 icon_seamless_eps google_weathernext2_ensemble) +declare -A LABEL=([ncep_gefs025]=GEFS [icon_seamless_eps]=ICON [google_weathernext2_ensemble]=Google) + +# pick DAYS: sets $line (the --brief output) and $model. IFS unless it is STALE; a fallback only if its +# download names its run (so it can be checked) and isn't STALE; otherwise IFS anyway. +pick() { + local m l head first="" first_model="" err="" + for m in "${MODELS[@]}"; do + if ! l=$(ens-forecast --brief "$1" --model "$m" 2>&1); then + [[ -z $err ]] && err=$l + continue + fi + l=$(grep -v '^note: ' <<< "$l") # e.g. "note: ... forecasts only 10 days" (on stderr, models < 14 days) + [[ -z $first ]] && first=$l first_model=$m + head=${l%%: *} + [[ $m != "${MODELS[0]}" && $head != *", run "* ]] && continue # unlabelled fallback: can't check + if [[ $head != *STALE* ]]; then + line=$l model=$m + return 0 + fi + done + if [[ -n $first ]]; then line=$first model=$first_model; return 0; fi + line=$err + return 1 +} if [ "$1" = "week" ]; then - if ! line=$(ens-forecast --brief 7 2>&1); then + if ! pick 7; then notify-send "ens-forecast" "$line" exit fi @@ -17,6 +46,10 @@ if [ "$1" = "week" ]; then exit fi -line=$(ens-forecast --brief 1 2>/dev/null) || exit 0 +pick 1 2>/dev/null || exit 0 read -r day temps rain <<< "${line#*: }" -echo "$day ${temps%C} "$'\uf043'" $rain" +label="" +[[ $model != "${MODELS[0]}" ]] && label="${LABEL[$model]:-$model} " +stale="" +[[ ${line%%: *} == *STALE* ]] && stale=" !" +echo "$label$day ${temps%C} "$''" $rain$stale"