#!/bin/sh # 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) [ -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 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" else echo "${weather:-⛅ -- }" fi curl -s "$WTTR_URL" > "$WTTR_CACHE"