From a3398adda85e05a47e0c505aa49b24cb783d9ec1 Mon Sep 17 00:00:00 2001 From: Curtis Jones Date: Tue, 10 Sep 2024 10:27:46 -0400 Subject: [PATCH 1/2] exported bash functions so that we can add timeout this allows for quitting early if wttr.in is having an issue. recently wttr.in had an issue where it would hang on requests, causing the status bar to fail. --- scripts/weather.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index 4b56c55f..d6461958 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -35,6 +35,7 @@ fetch_weather_information() #get weather display display_weather() { + fahrenheit=$1 if $fahrenheit; then display_weather='&u' # for USA system else @@ -66,13 +67,24 @@ forecast_unicode() fi } +export -f display_weather +export -f display_location +export -f forecast_unicode +export -f fetch_weather_information + main() { # process should be cancelled when session is killed if timeout 1 bash -c " Date: Mon, 23 Sep 2024 12:49:33 -0400 Subject: [PATCH 2/2] added timeout to the weather_wrapper.sh script If the last data that we received was actually an error message then we instead retry the connection every 1 minute until we get a valid status. This allows for faster recovery if the last check timed up with a network error. --- scripts/weather_wrapper.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/weather_wrapper.sh b/scripts/weather_wrapper.sh index 3356ce83..edf0a43f 100755 --- a/scripts/weather_wrapper.sh +++ b/scripts/weather_wrapper.sh @@ -11,6 +11,7 @@ fixedlocation=$3 DATAFILE=/tmp/.dracula-tmux-data LAST_EXEC_FILE="/tmp/.dracula-tmux-weather-last-exec" RUN_EACH=1200 +RETRY_EACH=60 TIME_NOW=$(date +%s) TIME_LAST=$(cat "${LAST_EXEC_FILE}" 2>/dev/null || echo "0") @@ -22,6 +23,10 @@ main() # Run weather script here $current_dir/weather.sh $fahrenheit $location "$fixedlocation" > "${DATAFILE}" echo "${TIME_NOW}" > "${LAST_EXEC_FILE}" + elif grep -q 'Unavailable\|Error' "${DATAFILE}" && [ "$(expr ${TIME_LAST} + ${RETRY_EACH})" -lt "${TIME_NOW}" ]; then + # Run weather script here + $current_dir/weather.sh $fahrenheit $location "$fixedlocation" > "${DATAFILE}" + echo "${TIME_NOW}" > "${LAST_EXEC_FILE}" fi cat "${DATAFILE}"