summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-07-21 14:47:55 +0200
committerRobert Günzler <r@gnzler.io>2020-07-21 14:47:55 +0200
commita2598ee49f9b88cba137a356dc3cb0520828b4a0 (patch)
tree85afbdc9d5ad62241836a778f7e956c5ea776852
parente7cfd58af25de9fe7e2a991baf57dfad4d1a0c10 (diff)
waybar: parse weather codes in the script
-rw-r--r--.config/waybar/config60
-rwxr-xr-x.config/waybar/modules/weather.sh24
2 files changed, 33 insertions, 51 deletions
diff --git a/.config/waybar/config b/.config/waybar/config
index 0edd528..27d90a6 100644
--- a/.config/waybar/config
+++ b/.config/waybar/config
@@ -152,54 +152,18 @@
     "custom/weather": {
 	"format": "{icon} {percentage}℃",
 	"format-icons": {
-            "113": "󰖙", // "Sunny",
-            "116": "󰖕", // "PartlyCloudy",
-            "119": "󰖐", // "Cloudy",
-            "122": "󰼯", // "VeryCloudy",
-            "143": "󰖑", // "Fog",
-            "176": "󰖗", // "LightShowers",
-            "179": "󰖒", // "LightSleetShowers",
-            "182": "󰖒", // "LightSleet",
-            "185": "󰖒", // "LightSleet",
-            "200": "󰖓", // "ThunderyShowers",
-            "227": "󰖘", // "LightSnow",
-            "230": "󰼶", // "HeavySnow",
-            "248": "󰖑", // "Fog",
-            "260": "󰖑", // "Fog",
-            "263": "󰖗", // "LightShowers",
-            "266": "󰖗", // "LightRain",
-            "281": "󰖒", // "LightSleet",
-            "284": "󰖒", // "LightSleet",
-            "293": "󰖗", // "LightRain",
-            "296": "󰖗", // "LightRain",
-            "299": "󰖖", // "HeavyShowers",
-            "302": "󰖖", // "HeavyRain",
-            "305": "󰖖", // "HeavyShowers",
-            "308": "󰖖", // "HeavyRain",
-            "311": "󰖒", // "LightSleet",
-            "314": "󰖒", // "LightSleet",
-            "317": "󰖒", // "LightSleet",
-            "320": "󰖘", // "LightSnow",
-            "323": "󰙿", // "LightSnowShowers",
-            "326": "󰙿", // "LightSnowShowers",
-            "329": "󰼶", // "HeavySnow",
-            "332": "󰼶", // "HeavySnow",
-            "335": "󰼶", //"HeavySnowShowers",
-            "338": "󰼶", //"HeavySnow",
-            "350": "󰖒", // "LightSleet",
-            "353": "󰖗", // "LightShowers",
-            "356": "󰖖", // "HeavyShowers",
-            "359": "󰖖", // "HeavyRain",
-            "362": "󰖒", // "LightSleetShowers",
-            "365": "󰖒", // "LightSleetShowers",
-            "368": "󰙿", // "LightSnowShowers",
-            "371": "󰼶", // "HeavySnowShowers",
-            "374": "󰖒", // "LightSleetShowers",
-            "377": "󰖒", // "LightSleet",
-            "386": "󰖓", // "ThunderyShowers",
-            "389": "󰖓", // "ThunderyHeavyRain",
-            "392": "󰖓", // "ThunderySnowShowers",
-            "395": "󰼶", // "HeavySnowShowers",
+            "sunny": "󰖙",
+            "partlycloudy": "󰖕",
+            "cloudy": "󰖐",
+            "verycloudy": "󰼯",
+            "fog": "󰖑",
+            "lightrain": "󰖗",
+            "heavyrain": "󰖖",
+            "hail": "󰖒",
+            "thunder": "󰖓",
+            "lightsnow": "󰖘",
+            "heavysnow": "󰼶",
+            "snowrain": "󰙿",
         },
 	"exec": "$HOME/.config/waybar/modules/weather.sh Berlin",
 	"interval": 600,
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) }'