diff --git a/modules/module_weather b/modules/module_weather index 8349186..0be3fee 100755 --- a/modules/module_weather +++ b/modules/module_weather @@ -7,12 +7,25 @@ module_config [ "$ENABLE_ITEM5" = "true" ] || exit command -v curl > /dev/null || exit -WEATHER_FULL="$(echo "$(curl -s wttr.in/?format="%C" || exit), $(curl -s wttr.in/?format=3 | sed 's/.* //; s/.*\(.....\)/\1/')")" -echo "$WEATHER_FULL" | grep -qE "Unknown location|| ," && exit +# weather data +DATA1="$(curl -s wttr.in/?format="%C")" +DATA2="$(curl -s wttr.in/?format=3 | sed 's/.* //; s/.*\(.....\)/\1/')" + +# if no internet connection/it failed to download +[ -z "$DATA1" ] && printf "No internet connection.\n" > /tmp/module_weather_log && exit 1 + +# full data +# TODO: formatting support +WEATHER_FULL="$(echo "$DATA1, $DATA2")" + +# if unknown location or tag, exit +echo "$WEATHER_FULL" | grep -qE "Unknown location|" && printf "Invalid data.\n" > /tmp/module_weather_log && exit 1 GETICON() { + # default to no icon, we'll override this with $ITEM5_ICON if -z ICON="" + # check icon echo "$WEATHER_FULL" | grep -qE "Cloudy|cloudy" && ICON=CLOUDY echo "$WEATHER_FULL" | grep -qE "Windy|windy|wind" && ICON=WINDY echo "$WEATHER_FULL" | grep -qE "Fog|fog|Foggy|foggy" && ICON=FOGGY