Handle stale data in ens-forecast brief in xmobar
This commit is contained in:
@@ -1,9 +1,38 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Next day from ens-forecast for xmobar, e.g. "Sat 19/10° 39%" (today before 18:00, then tomorrow)
|
# 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)
|
# 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 [ "$1" = "week" ]; then
|
||||||
if ! line=$(ens-forecast --brief 7 2>&1); then
|
if ! pick 7; then
|
||||||
notify-send "ens-forecast" "$line"
|
notify-send "ens-forecast" "$line"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@@ -17,6 +46,10 @@ if [ "$1" = "week" ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
line=$(ens-forecast --brief 1 2>/dev/null) || exit 0
|
pick 1 2>/dev/null || exit 0
|
||||||
read -r day temps rain <<< "${line#*: }"
|
read -r day temps rain <<< "${line#*: }"
|
||||||
echo "$day ${temps%C} "$'\uf043'" $rain"
|
label=""
|
||||||
|
[[ $model != "${MODELS[0]}" ]] && label="${LABEL[$model]:-$model} "
|
||||||
|
stale=""
|
||||||
|
[[ ${line%%: *} == *STALE* ]] && stale=" <fc=#f7768e>!</fc>"
|
||||||
|
echo "$label$day ${temps%C} "$''" $rain$stale"
|
||||||
|
|||||||
Reference in New Issue
Block a user