aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/sb-forecast
diff options
context:
space:
mode:
authorawy <awy@awy.one>2025-07-30 23:27:54 +0300
committerawy <awy@awy.one>2025-07-30 23:27:54 +0300
commit9d227c8cc3f54e2b6baa40c6342814e0179a9fc2 (patch)
treee79d7206b3c7e6779d126fc7b5ab2430e6fb8aa8 /.local/bin/statusbar/sb-forecast
parent35725a6698c758e11be5dba9ae4eaf854b442854 (diff)
downloadhyprdots-9d227c8cc3f54e2b6baa40c6342814e0179a9fc2.tar.gz
update
Diffstat (limited to '.local/bin/statusbar/sb-forecast')
-rwxr-xr-x.local/bin/statusbar/sb-forecast65
1 files changed, 0 insertions, 65 deletions
diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast
deleted file mode 100755
index eb07dfe..0000000
--- a/.local/bin/statusbar/sb-forecast
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/sh
-
-# Displays today's precipication chance (ā˜”), and daily low (🄶) and high (šŸŒž).
-# Usually intended for the statusbar.
-
-url="${WTTRURL:-wttr.in}"
-weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
-
-# Get a weather report from 'wttr.in' and save it locally.
-getforecast() { { rg -q -m1 '^up$' /sys/class/net/w*/operstate || rg -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
- curl -sf "$url/$LOCATION" --output "$weatherreport" && touch "$weatherreport"
-}
-
-# Forecast should be updated only once a day.
-checkforecast() {
- [ "$(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
- rg -wo "[0-9]*%" | # Find a sequence of digits followed by '%'
- sort -rn | # Sort in descending order
- head -1q # Extract first line
-}
-
-getdailyhighlow() {
- echo "$weatherdata" | sed '13q;d' | # Extract line 13 from file
- rg -o "m[-+]?[0-9]+" | # Find temperatures in the format "m<signed number>"
- sed 's/[+m]//g' | # Remove '+' and 'm'
- sort -g | # Sort in ascending order
- sed -e 1b -e '$!d' # Extract the first and last lines
-}
-
-readfile() { weatherdata="$(bat "$weatherreport")" ;}
-
-showweather() {
- readfile
- # shellcheck disable=SC2046,SC2183
- printf "ā˜”%s ā„ļø%s° šŸŒž%s°\n" "$(getprecipchance)" $(getdailyhighlow)
-}
-
-case $BLOCK_BUTTON in
- 1) setsid -f "$TERMINAL" -e less -Sf "$weatherreport" >/dev/null 2>&1 ;;
- 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" ;;
- 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;;
-esac
-
-# shellcheck disable=SC2015
-checkforecast && showweather ||
- ( flock -n 9 &&
- ( tries=0; while [ $tries -ne 100 ]; do
- getforecast && break ||
- { tries=$((tries+1)); sleep .1; }
- done
- ! checkforecast &&
- until getforecast; do sleep 60; done
- pkill -RTMIN+5 "${STATUSBAR:-waybar}"
- ) &
- echo ) 9>"${XDG_RUNTIME_DIR}/sb-forecast.lock"