From f012b3ea4a57e3749e0ffb225210c95a93a25f6a Mon Sep 17 00:00:00 2001 From: gutmet Date: Mon, 15 Mar 2021 21:38:14 +0100 Subject: [PATCH] handle missing weather data --- dwmstatus.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/dwmstatus.sh b/dwmstatus.sh index dcb74ec..d469dd8 100755 --- a/dwmstatus.sh +++ b/dwmstatus.sh @@ -4,16 +4,19 @@ while true; do time=`date +"🕑 %d.%m. %H:%M"` weatherdata=`cat weatherdump` - current=`echo "$weatherdata" | jq -r '.current_condition | .[0]'` - temp=`echo "$current" | jq -r '.temp_C'` - weatherDesc=`echo "$current" | jq -r '.weatherDesc | .[0].value'` - wind=`echo "$current" | jq -r '.windspeedKmph'` - astronomy=`echo "$weatherdata" | jq -r '.weather | .[0] .astronomy | .[0]'` - moonphase=`echo "$astronomy" | jq -r '.moon_phase'` - sunrise=`echo "$astronomy" | jq -r '.sunrise'` - sunset=`echo "$astronomy" | jq -r '.sunset'` - weather="🌡 $temp°C $weatherDesc $wind""km/h Daylight $sunrise-$sunset, Moon $moonphase" - + if [ -z "$weatherdata" ]; then + weather="No weather data..." + else + current=`echo "$weatherdata" | jq -r '.current_condition | .[0]'` + temp=`echo "$current" | jq -r '.temp_C'` + weatherDesc=`echo "$current" | jq -r '.weatherDesc | .[0].value'` + wind=`echo "$current" | jq -r '.windspeedKmph'` + astronomy=`echo "$weatherdata" | jq -r '.weather | .[0] .astronomy | .[0]'` + moonphase=`echo "$astronomy" | jq -r '.moon_phase'` + sunrise=`echo "$astronomy" | jq -r '.sunrise'` + sunset=`echo "$astronomy" | jq -r '.sunset'` + weather="🌡 $temp°C $weatherDesc $wind""km/h Daylight $sunrise-$sunset, Moon $moonphase" + fi xsetroot -name "$weather $time " sleep 10 done