From 8e7643f352079e80ff9a202f816b905529aa547f Mon Sep 17 00:00:00 2001 From: Salt Date: Wed, 13 Sep 2017 00:22:41 -0500 Subject: [PATCH] Polybar: Add scripted weather module --- .config/polybar/config | 7 ++++++- .config/polybar/weather.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 .config/polybar/weather.sh diff --git a/.config/polybar/config b/.config/polybar/config index 9dacb163..5e4e4373 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -103,7 +103,7 @@ background = #001d2021 modules-left = i3 bspwm | modules-center = xwindow-label -modules-right = | temperature-label-alert mpd-mini wlan-network-mini volume-ramp-mini battery-ramp-mini | date-mini +modules-right = | temperature-label-alert mpd-mini wlan-network-mini volume-ramp-mini battery-ramp-mini | weather-mini date-mini #======================================== # MODULES @@ -420,6 +420,11 @@ ramp-volume-0 =  ramp-volume-1 =  ramp-volume-2 =  +[module/weather-mini] +type = custom/script +exec = $HOME/.config/polybar/weather.sh +interval = 60 + [module/wlan-network] inherit = template/module/network format-connected-prefix = " " diff --git a/.config/polybar/weather.sh b/.config/polybar/weather.sh new file mode 100755 index 00000000..a9b45f94 --- /dev/null +++ b/.config/polybar/weather.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +source $HOME/.config/polybar/location.sh + +# write xml to variable +w_xml=$(curl --silent "http://weather.tuxnet24.de/?id=$location&mode=xml&unit=imperial"); +# get fields from xml via xmllint | xargs for trimming +# weather description +w_txt=$(xmllint --xpath "string(//current_text)" - <<<"$w_xml" | xargs); +# temperature | remove spaces from text (°C prepended by space) +w_tpc=$(xmllint --xpath "string(//current_temp)" - <<<"$w_xml" | xargs); w_tpc=${w_tpc//[[:blank:]]/}; +# further fields not used atm +# w_tph=$(xmllint --xpath "string(//current_temp_high)" - <<<"$w_xml" | xargs); +# w_tpl=$(xmllint --xpath "string(//current_temp_low)" - <<<"$w_xml" | xargs); + +# set $w_sym according to $w_txt +if [ "$w_txt" == "Sunny" ]; then w_sym=""; +elif [ "$w_txt" == "Mostly Sunny" ]; then w_sym="~"; +elif [ "$w_txt" == "Showers" ]; then w_sym=""; +elif [ "$w_txt" == "Clear" ]; then w_sym=""; +elif [ "$w_txt" == "Thunderstorms" ]; then w_sym=""; +elif [ "$w_txt" == "Scattered Thunderstorms" ]; then w_sym="~"; +elif [ "$w_txt" == "Isolated Thundershovers" ]; then w_sym="~~"; +elif [ "$w_txt" == "Cloudy" ]; then w_sym=""; +elif [ "$w_txt" == "Mostly Cloudy" ]; then w_sym="~"; +elif [ "$w_txt" == "Partly Cloudy" ]; then w_sym=""; +elif [ "$w_txt" == "Breezy" ]; then w_sym=""; +# if unknown text, set text instead of symbol +else w_sym=$w_txt; +fi +# output +echo "$w_sym"" ""$w_tpc"; + +exit 0