From 0b0b3814b109dbb2acbb3262273f443a00b2dfa7 Mon Sep 17 00:00:00 2001 From: Edvid Date: Wed, 29 May 2024 00:22:28 +0200 Subject: [PATCH] Suggested fallback for failing wttr.in weather API --- scripts/weather.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index e8bbd8f0..583afd63 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -23,7 +23,13 @@ fetch_weather_information() { display_weather=$1 # it gets the weather condition textual name (%C), and the temperature (%t) - curl -sL wttr.in/${fixedlocation// /%20}\?format="%C+%t$display_weather" + api_response=$(curl -sL wttr.in/${fixedlocation// /%20}\?format="%C+%t$display_weather") + + if [[ $api_response = "Unknown location;"* ]]; then + echo "Unknown location error" + else + echo $api_response + fi } #get weather display