From 8c24921832b2b6dc95bbb41dbfe2de7ff4fcf877 Mon Sep 17 00:00:00 2001 From: awy Date: Tue, 27 Aug 2024 03:44:14 +0300 Subject: update --- .local/bin/statusbar/sb-forecast | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 .local/bin/statusbar/sb-forecast (limited to '.local/bin/statusbar/sb-forecast') diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast new file mode 100755 index 0000000..42442cf --- /dev/null +++ b/.local/bin/statusbar/sb-forecast @@ -0,0 +1,52 @@ +#!/bin/sh + +# Displays today's precipication chance (ā˜”), and daily low (šŸ„¶) and high (šŸŒž). +# Usually intended for the statusbar. +LOCATION="Moscow" +url="${WTTRURL:-wttr.in}" +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; } + +getprecipchance() { + echo "$weatherdata" | sed '16q;d' | # Extract line 16 from file + grep -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 + grep -o "m\\([-+]\\)*[0-9]\\+" | # Find temperatures in the format "m" + 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="$(cat "$weatherreport")" ;} + +showweather() { + readfile + printf "ā˜”%s šŸ„¶%sĀ° šŸŒž%sĀ°\n" "$(getprecipchance)" $(getdailyhighlow) +} + +openterm() { + hyprctl dispatch exec "[float; size 1800 1300;]" 'kitty -e sh -c "curl wttr.in; read _"' +} + +sendnotif() { + notify-send "šŸŒˆ Weather module" "Left click for full forecast." +} + +if [ ! -n "$1" ]; then + getforecast + showweather +else + if [ "$1" -eq 1 ]; then + openterm + elif [ "$1" -eq 3 ]; then + sendnotif + fi +fi + -- cgit v1.2.3