From 2ef9b580fc0cbdbff93ae01caecf586df4d35894 Mon Sep 17 00:00:00 2001 From: steven-na Date: Thu, 30 Apr 2026 21:55:10 -0700 Subject: Weather upgrade && fixed bug introduced in curstom scrolloff --- arch/eww/.config/eww/scripts/weather-fetch | 59 +++++++++++++++++++++++------ arch/eww/.config/eww/scripts/weather-notify | 24 ++++++++++++ 2 files changed, 72 insertions(+), 11 deletions(-) (limited to 'arch/eww/.config') diff --git a/arch/eww/.config/eww/scripts/weather-fetch b/arch/eww/.config/eww/scripts/weather-fetch index 257dee4..8fa53ac 100755 --- a/arch/eww/.config/eww/scripts/weather-fetch +++ b/arch/eww/.config/eww/scripts/weather-fetch @@ -3,7 +3,7 @@ loc_file="$HOME/.config/eww/.weather-location" loc=$(cat "$loc_file" 2>/dev/null | xargs | sed 's/ /%20/g') -url="wttr.in/${loc}?format=j1" # empty loc → wttr.in/?format=j1 → IP fallback +url="wttr.in/${loc}?format=j1" data=$(curl -sf "$url") [[ -z "$data" ]] && echo "?°F" && exit 1 @@ -11,16 +11,53 @@ data=$(curl -sf "$url") temp=$(echo "$data" | jq -r '.current_condition[0].temp_F') code=$(echo "$data" | jq -r '.current_condition[0].weatherCode') -case "$code" in - 113) icon="󰖙" ;; - 116) icon="󰖕" ;; - 119|122) icon="󰖐" ;; - 143|248|260) icon="󰖑" ;; - 200|386|389|392|395) icon="󰖓" ;; - 227|230|323|326|329|332|335|338|368|371) icon="󰖘" ;; - 182|185|281|284|311|314|317|320|350|362|365|374|377) icon="󰖒" ;; - *) icon="󰖗" ;; -esac +# ── Night check ──────────────────────────────────────────────────────────── +sunset_raw=$(echo "$data" | jq -r '.weather[0].astronomy[0].sunset') +sunset_epoch=$(date -d "today $sunset_raw" +%s 2>/dev/null) +now_epoch=$(date +%s) +is_night=false +[[ $now_epoch -ge $sunset_epoch ]] && is_night=true + +# ── Moon phase ───────────────────────────────────────────────────────────── +moon_icon() { + local ref; ref=$(date -d "2000-01-06" +%s) # known new moon + local days=$(( ($(date +%s) - ref) / 86400 )) + local phase=$(( days % 29 )) + if [[ $phase -le 1 ]]; then echo "󰽤" # new + elif [[ $phase -le 7 ]]; then echo "󰽧" # waxing crescent + elif [[ $phase -le 8 ]]; then echo "󰽡" # first quarter + elif [[ $phase -le 14 ]]; then echo "󰽨" # waxing gibbous + elif [[ $phase -le 15 ]]; then echo "󰽢" # full + elif [[ $phase -le 21 ]]; then echo "󰽦" # waning gibbous + elif [[ $phase -le 22 ]]; then echo "󰽣" # last quarter + else echo "󰽥" # waning crescent + fi +} + +# ── Icon selection ───────────────────────────────────────────────────────── +if $is_night; then + case "$code" in + 113) icon=$(moon_icon) ;; # clear → moon phase + 116) icon="" ;; # nf-fa-cloud_moon + 119|122) icon="" ;; # overcast (no moon visible) + 143|248|260) icon="" ;; # fog/mist + 200|386|389|392|395) icon="" ;; # nf-fa-cloud_moon_rain (thunder) + 227|230|323|326|329|332|335|338|368|371) icon="" ;; # snow (no night variant needed) + 182|185|281|284|311|314|317|320|350|362|365|374|377) icon="" ;; # nf-fa-cloud_moon_rain (sleet) + *) icon="" ;; # nf-fa-cloud_moon_rain (rain) + esac +else + case "$code" in + 113) icon="󰖙" ;; + 116) icon="󰖕" ;; + 119|122) icon="󰖐" ;; + 143|248|260) icon="" ;; + 200|386|389|392|395) icon="" ;; + 227|230|323|326|329|332|335|338|368|371) icon="" ;; + 182|185|281|284|311|314|317|320|350|362|365|374|377) icon="" ;; + *) icon="" ;; + esac +fi sign=$([ "$temp" -ge 0 ] && echo "+" || echo "") echo "${sign}${temp}°F ${icon}" diff --git a/arch/eww/.config/eww/scripts/weather-notify b/arch/eww/.config/eww/scripts/weather-notify index ab78acb..fc95df0 100755 --- a/arch/eww/.config/eww/scripts/weather-notify +++ b/arch/eww/.config/eww/scripts/weather-notify @@ -14,6 +14,26 @@ desc=$(echo "$data" | jq -r '.current_condition[0].weatherDesc[0].value') high=$(echo "$data" | jq -r '.weather[0].maxtempF') low=$(echo "$data" | jq -r '.weather[0].mintempF') +# ── Night / moon ─────────────────────────────────────────────────────────── +sunset_raw=$(echo "$data" | jq -r '.weather[0].astronomy[0].sunset') +sunset_epoch=$(date -d "today $sunset_raw" +%s 2>/dev/null) +is_night=false +[[ $(date +%s) -ge $sunset_epoch ]] && is_night=true + +moon_phase() { + local ref; ref=$(date -d "2000-01-06" +%s) + local phase=$(( ( ($(date +%s) - ref) / 86400 ) % 29 )) + if [[ $phase -le 1 ]]; then echo "New Moon" + elif [[ $phase -le 7 ]]; then echo "Waxing Crescent" + elif [[ $phase -le 8 ]]; then echo "First Quarter" + elif [[ $phase -le 14 ]]; then echo "Waxing Gibbous" + elif [[ $phase -le 15 ]]; then echo "Full Moon" + elif [[ $phase -le 21 ]]; then echo "Waning Gibbous" + elif [[ $phase -le 22 ]]; then echo "Last Quarter" + else echo "Waning Crescent" + fi +} + sign() { [ "$1" -ge 0 ] && echo "+" || echo ""; } line1="$(sign $temp)${temp}°F, ${desc}" @@ -22,3 +42,7 @@ line2="Feels $(sign $feels)${feels}° · ↑$(sign $high)${high} ↓$(sign $low) notify-send --urgency=low --expire-time=5000 \ --icon=weather-clear \ "Weather" "${line1}\n${line2}" + +$is_night && notify-send --urgency=low --expire-time=5000 \ + --icon=weather-clear \ + "Moon" "$(moon_phase)" -- cgit v1.2.3