summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/statusbar')
-rwxr-xr-x.local/bin/statusbar/i3weather26
1 files changed, 18 insertions, 8 deletions
diff --git a/.local/bin/statusbar/i3weather b/.local/bin/statusbar/i3weather
index d008deb..c894be6 100755
--- a/.local/bin/statusbar/i3weather
+++ b/.local/bin/statusbar/i3weather
@@ -2,20 +2,30 @@
# weather module for i3blocks
# output is set to 'WEATHER UNAVAILABLE' in case wttr.in is unreachable
+WTTR_CACHE_DIR="/tmp"
+WTTR_CACHE="$WTTR_CACHE_DIR/wttr.in"
+WTTR_TXT="$WTTR_CACHE_DIR/wttr.txt"
+WTTR_LOCATION="Vasai"
+WTTR_URL="https://wttr.in/$WTTR_LOCATION"
+
case "$BLOCK_BUTTON" in
- '') ;;
+ '') true ;;
1)
- $TERMINAL -e less -r ~/.cache/weather.txt & sleep 0.3
- i3-msg 'move to workspace "12: Weather"; workspace "12: Weather"' >/dev/null 2>&1
+ [ -f "$WTTR_CACHE" ] || BLOCK_BUTTON=5 i3weather
+ sed 's,\x1B\[[0-9;]*[a-zA-z],,g' "$WTTR_CACHE" > "$WTTR_TXT"
+ st -c "dropdown_weather" \
+ -g "$(wc -L < "$WTTR_TXT")x38" \
+ -e less -r "$WTTR_CACHE" & sleep 0.3
;;
2) $TERMINAL -e nvim "$0" ;;
*) notify-send "⛅ Refreshing weather info..." ;;
esac
-HTTP_WEATHER="https://wttr.in/Vasai"
-# weather="$(curl -s "$HTTP_WEATHER?format=%c%C++❄️+%t++☀️+%f++🌬️+%w")"
-weather="$(curl -Ss "$HTTP_WEATHER?0&T&Q" | cut -c 16- | head -2 |
- xargs echo "$(curl -s "$HTTP_WEATHER?format=%c")")"
+case "$1" in
+ 1) weather="$(curl -s "$WTTR_URL?format=%c")$WTTR_LOCATION $(curl -Ss "$WTTR_URL?0&T&Q" | sed -E '2,3!d; s/.{16}(.{13}).*/\1/; s/ {4}$//' | tr -d '\n')" ;;
+ 2) weather="$(curl -s "$WTTR_URL?format=%c%C")" ;;
+ *) weather="$(curl -s "$WTTR_URL?format=%c") $(curl -Ss "$WTTR_URL?0&T&Q" | cut -c 16- | head -2)" ;;
+esac
if [ "$(echo "$weather" | grep -Ec "(Unknown|curl|HTML)")" -gt 0 ]; then
echo "WEATHER UNAVAILABLE"
@@ -23,5 +33,5 @@ else
echo "${weather:-⛅ -- }"
fi
-curl -s "$HTTP_WEATHER" > ~/.cache/weather.txt
+curl -s "$WTTR_URL" > "$WTTR_CACHE"