From a2598ee49f9b88cba137a356dc3cb0520828b4a0 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Tue, 21 Jul 2020 14:47:55 +0200 Subject: waybar: parse weather codes in the script --- .config/waybar/modules/weather.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to '.config/waybar/modules/weather.sh') diff --git a/.config/waybar/modules/weather.sh b/.config/waybar/modules/weather.sh index 9f7780d..210c20a 100755 --- a/.config/waybar/modules/weather.sh +++ b/.config/waybar/modules/weather.sh @@ -9,11 +9,29 @@ if [ -n "$REPORT" ]; then exit 0 fi -curl -s wttr.in/"${loc}"?format=j1 \ - | jq \ +data="$(curl -s wttr.in/"${loc}"?format=j1)" + +class= +case "$(echo "${data}" | jq -r '.current_condition[].weatherCode')" in +113) class="sunny" ;; +116) class="partlycloudy" ;; +119) class="cloudy" ;; +122) class="verycloudy" ;; +143|248|260) class="fog" ;; +176|263|266|293|296|353) class="lightrain" ;; +179|182|185|281|284|311|314|317|350|362|365|374|377) class="hail" ;; +200|386|389|392) class="thunder" ;; +227|320) class="lightsnow" ;; +230|329|332|335|338|371|395) class="heavysnow" ;; +299|302|305|308|356|359): class="heavyrain" ;; +323|326|368) class="snowrain" ;; +esac + +echo "${data}" | jq \ --raw-output \ --unbuffered \ --compact-output \ + --arg class "${class}" \ --arg tooltip "$(curl -s v2.wttr.in/"${loc}"?ATFQ | tail -n5)" \ - '.current_condition[] | { text: .weatherDesc[0].value, percentage: (.temp_C | tonumber), class: .weatherCode, alt: .weatherCode, tooltip: ($tooltip) }' + '.current_condition[] | { text: .weatherDesc[0].value, percentage: (.temp_C | tonumber), class: $class, alt: $class, tooltip: ($tooltip) }' -- cgit 1.4.1