aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/sb-forecast
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/statusbar/sb-forecast')
-rwxr-xr-x.local/bin/statusbar/sb-forecast13
1 files changed, 10 insertions, 3 deletions
diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast
index ebbdf58..113a3ba 100755
--- a/.local/bin/statusbar/sb-forecast
+++ b/.local/bin/statusbar/sb-forecast
@@ -9,6 +9,12 @@ weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
# Get a weather report from 'wttr.in' and save it locally.
getforecast() { timeout --signal=1 2s curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; }
+# Forecast should be updated only once a day.
+checkforecast() {
+ [ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null |
+ cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
+}
+
getprecipchance() {
echo "$weatherdata" | sed '16q;d' | # Extract line 16 from file
grep -wo "[0-9]*%" | # Find a sequence of digits followed by '%'
@@ -36,15 +42,16 @@ openterm() {
}
case $1 in
- 1) hyprctl dispatch exec "[float; size 1800 1300;]" 'kitty -e sh -c "curl wttr.in/Moscow; read _"'
+ 1) hyprctl dispatch exec "[float; size 1450 1100;]" "kitty -e less -Sfr \"$weatherreport\""
;;
+ 2) getforecast && showweather ;;
3) notify-send "🌈 Weather module" "\- Left click for full forecast.
- Middle click to update forecast.
☔: Chance of rain/snow
🥶: Daily low
🌞: Daily high" ;;
- 6) kitty -e "$EDITOR" "$0" ;;
+ 6) hyprctl dispatch exec "kitty -e \"$EDITOR\" \"$0\"" ;;
esac
-getforecast
+checkforecast || getforecast
showweather