diff options
author | awy <awy@awy.one> | 2025-07-30 23:27:54 +0300 |
---|---|---|
committer | awy <awy@awy.one> | 2025-07-30 23:27:54 +0300 |
commit | 9d227c8cc3f54e2b6baa40c6342814e0179a9fc2 (patch) | |
tree | e79d7206b3c7e6779d126fc7b5ab2430e6fb8aa8 | |
parent | 35725a6698c758e11be5dba9ae4eaf854b442854 (diff) | |
download | hyprdots-9d227c8cc3f54e2b6baa40c6342814e0179a9fc2.tar.gz |
update
-rwxr-xr-x | .local/bin/dmenuunicode | 2 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-forecast | 65 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-weather | 85 | ||||
-rw-r--r-- | .local/share/extras/weather_codes | 48 |
4 files changed, 134 insertions, 66 deletions
diff --git a/.local/bin/dmenuunicode b/.local/bin/dmenuunicode index a9d94e9..bfb190d 100755 --- a/.local/bin/dmenuunicode +++ b/.local/bin/dmenuunicode @@ -3,7 +3,7 @@ # The famous "get a menu of emojis to copy" script. # Get user selection via rofi -dmenu from emoji file. -chosen=$(cut -d ';' -f1 ~/.local/share/larbs/chars/* | rofi -dmenu -i -l 30 | sed "s/ .*//") +chosen=$(cut -d ';' -f1 ~/.local/share/extras/chars/* | rofi -dmenu -i -l 30 | sed "s/ .*//") # Exit if none chosen. [ -z "$chosen" ] && exit 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" diff --git a/.local/bin/statusbar/sb-weather b/.local/bin/statusbar/sb-weather new file mode 100755 index 0000000..d5fa97b --- /dev/null +++ b/.local/bin/statusbar/sb-weather @@ -0,0 +1,85 @@ +#!/bin/sh +arg=$1 +report=~/.cache/weather_report.json + +ifinstalled jq + +# 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 "wttr.in/?format=j1" --output "$report" && touch "$report" +} + +# Forecast should be updated only once a day. +checkforecast() { + [ "$(stat -c %y "$report" 2>/dev/null | + cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] +} + +# Function to get weather emoji from code +get_weather_emoji() { + local code="$1" + grep "^$code " ~/.local/share/extras/weather_codes | awk '{print $2}' +} + +showweather(){ + temp=$(jq -r '.current_condition[0].temp_C' $report) + code=$(jq -r '.current_condition[0].weatherCode' $report) + rainchance=$(jq '.weather[].hourly[].chanceofrain | tonumber' $report | sort -n | tail -n 1) + + emoji=$(get_weather_emoji "$code") + case "$arg" in + weather) + case 1 in + $((temp >= 30)) ) class="very_hot" ;; + $((temp >= 26)) ) class="hot" ;; + $((temp >= 21)) ) class="warm" ;; + $((temp >= 16)) ) class="mild" ;; + $((temp >= 11)) ) class="cool" ;; + $((temp >= 6)) ) class="chilly" ;; + $((temp >= 0)) ) class="cold" ;; + $((temp < 0)) ) class="below_zero" ;; + * ) echo unavailable && exit ;; + esac + output="$emoji$tempΒ°C" + ;; + rain) + case 1 in + $((rainchance >= 90)) ) class="ninety" ;; + $((rainchance >= 70)) ) class="seventy" ;; + $((rainchance >= 50)) ) class="fifty" ;; + $((rainchance >= 30)) ) class="thirty" ;; + $((rainchance >= 10)) ) class="ten" ;; + $((rainchance > 0)) ) class="zero" ;; + $((rainchance <= 0)) ) printf '' && exit ;; + * ) echo unavailable && exit ;; + esac + output="ο©$rainchance%" + ;; + *) + echo "Usage: $0 {weather|rain}" + exit 1 + ;; + esac + printf '{"text": "%s", "class": "%s" }' "$output" "$class" +} + +case $BLOCK_BUTTON in + 2) getforecast && showweather ;; + 3) notify-send "π Weather module" "\- Middle click to update forecast. +β: Chance of rain/snow +π: Current temperature" ;; + 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" diff --git a/.local/share/extras/weather_codes b/.local/share/extras/weather_codes new file mode 100644 index 0000000..6a192eb --- /dev/null +++ b/.local/share/extras/weather_codes @@ -0,0 +1,48 @@ +113 βοΈ +116 β
+119 βοΈ +122 βοΈ +143 βοΈ +176 π§οΈ +179 π§οΈ +182 π§οΈ +185 π§οΈ +200 βοΈ +227 π¨οΈ +230 π¨οΈ +248 βοΈ +260 βοΈ +263 π§οΈ +266 π§οΈ +281 π§οΈ +284 π§οΈ +293 π§οΈ +296 π§οΈ +299 π§οΈ +302 π§οΈ +305 π§οΈ +308 π§οΈ +311 π§οΈ +314 π§οΈ +317 π§οΈ +320 π¨οΈ +323 π¨οΈ +326 π¨οΈ +329 βοΈ +332 βοΈ +335 βοΈ +338 βοΈ +350 π§οΈ +353 π§οΈ +356 π§οΈ +359 π§οΈ +362 π§οΈ +365 π§οΈ +368 π§οΈ +371 βοΈ +374 π¨οΈ +377 π¨οΈ +386 π¨οΈ +389 π¨οΈ +392 π§οΈ +395 βοΈ |