This commit is contained in:
2025-06-22 08:15:06 +02:00
parent 12aaf87a46
commit 5539982abd
26 changed files with 267 additions and 121 deletions

View File

@@ -7,7 +7,7 @@
background-color: $bg;
font-family: 'Font Awesome 6 Free';
border-radius: 20px;
border: 3px solid $blue;
border: 2px solid $blue;
}
.date-box {
@@ -55,6 +55,12 @@
font-size: 60px;
}
.weather-updatetime {
color: $fg-alt;
font-size: 12px;
margin-top: 10px;
}
.stats-box {
background-color: $gray-alt;
margin: 20px 20px 0px 20px;

View File

@@ -4,9 +4,10 @@
(defpoll date :interval "1s" "date '+%A, %B %d'")
(deflisten notifications-cards "Main/scripts/logger.zsh subscribe")
(defpoll notifications-crits :interval "1s" "Main/scripts/logger.zsh crits")
(defpoll weather-icon :interval "20m" "Main/scripts/weather --icon")
(defpoll weather-temp :interval "20m" "Main/scripts/weather --temp")
(defpoll weather-desc :interval "20m" "Main/scripts/weather --stat")
(defpoll weather-icon :interval "5m" "Main/scripts/weather --icon")
(defpoll weather-temp :interval "5m" "Main/scripts/weather --temp")
(defpoll weather-desc :interval "5m" "Main/scripts/weather --stat")
(defpoll weather-updatetime :interval "5m" "Main/scripts/weather --updatetime")
(deflisten weather-color :initial "#7aa2f7" "Main/scripts/weather --hex")
(defpoll calendar-day :interval "20h" "+%d")
(defpoll calendar-year :interval "20h" "+%Y")
@@ -42,8 +43,9 @@
(label :class "time" :text time)
(label :class "date" :text date))
(box :class "weather-box" :space-evenly "false" :hexpand "true" :orientation "v"
(label :class "weather-desc" :halign "start" :text weather-desc)
(label :class "weather-temp" :halign "start" :text weather-temp)
(label :class "weather-desc" :halign "start" :text weather-desc)
(label :class "weather-temp" :halign "start" :text weather-temp)
(label :class "weather-updatetime" :halign "start" :text weather-updatetime)
(label :class "weather-icon" :halign "end" :valign "end" :text weather-icon :style "color: ${weather-color}")))
(box :class "second-row" :orientation "h" :space-evenly "false"
(box :class "stats-box" :space-evenly "false" :orientation "v" :spacing 8

View File

@@ -6,6 +6,7 @@ cache_weather_stat=${cache_dir}/weather-stat
cache_weather_degree=${cache_dir}/weather-degree
cache_weather_hex=${cache_dir}/weather-hex
cache_weather_icon=${cache_dir}/weather-icon
cache_weather_updatetime=${cache_dir}/weather-updatetime
if [[ -z "$OPENWEATHER_API_KEY" ]]; then
echo "Please set the OPENWEATHER_API_KEY environment variable."
@@ -33,8 +34,9 @@ fi
## Get data
get_weather_data() {
weather=`curl -sf "http://api.openweathermap.org/data/3.0/onecall?lat=${LAT}&lon=${LON}&exclude=minutely,hourly,daily&appid=${KEY}&units=${UNITS}" | jq -r ".current"`
echo ${weather}
weather=`curl -sf "http://api.openweathermap.org/data/3.0/onecall?lat=${LAT}&lon=${LON}&exclude=minutely,hourly,daily&appid=${KEY}&units=${UNITS}"`
echo ${weather} >&2
weather=$(echo "$weather" | jq -r ".current")
if [ ! -z "$weather" ]; then
weather_temp=`echo "$weather" | jq ".temp" | cut -d "." -f 1`
@@ -110,17 +112,38 @@ get_weather_data() {
echo "$weather_description" > ${cache_weather_stat}
echo "$weather_temp""°C" > ${cache_weather_degree}
echo "$weather_hex" > ${cache_weather_hex}
date "+%Y-%m-%d %H:%M:%S" | tee ${cache_weather_updatetime} >/dev/null
else
echo "Weather Unavailable" > ${cache_weather_stat}
echo " " > ${cache_weather_icon}
echo "-" > ${cache_weather_degree}
echo "#adadff" > ${cache_weather_hex}
date "+%Y-%m-%d %H:%M:%S" | tee ${cache_weather_updatetime} >/dev/null
fi
}
check_network() {
local max=12
local cnt=0
while [ $cnt -lt $max ]; do
if ping -c1 8.8.8.8 &>/dev/null || ping -c1 1.1.1.1 &>/dev/null; then
return 0
fi
echo "Waiting for network connection... (attempt: $((cnt + 1))/$max)" >&2
sleep 5
((cnt++))
done
echo "Network connection failed after $max attempts." >&2
return 1
}
## Execute
if [[ "$1" == "--getdata" ]]; then
get_weather_data
if check_network; then
get_weather_data
fi
elif [[ "$1" == "--icon" ]]; then
cat ${cache_weather_icon}
elif [[ "$1" == "--temp" ]]; then
@@ -129,4 +152,6 @@ elif [[ "$1" == "--hex" ]]; then
tail -F ${cache_weather_hex}
elif [[ "$1" == "--stat" ]]; then
cat ${cache_weather_stat}
elif [[ "$1" == "--updatetime" ]]; then
cat ${cache_weather_updatetime}
fi