summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/i3weather
blob: d008debbfa9a16ea69f9f87c5acee717ba1ce0b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
# weather module for i3blocks
# output is set to 'WEATHER UNAVAILABLE' in case wttr.in is unreachable

case "$BLOCK_BUTTON" in
	'') ;;
	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
		;;
	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")")"

if [ "$(echo "$weather" | grep -Ec "(Unknown|curl|HTML)")" -gt 0 ]; then
    echo "WEATHER UNAVAILABLE"
else
    echo "${weather:-⛅ -- }"
fi

curl -s "$HTTP_WEATHER" > ~/.cache/weather.txt