mirror of
https://codeberg.org/frosty/dotfiles.git
synced 2024-09-19 11:47:09 -04:00
(bin): create weather script
This commit is contained in:
parent
1129024dae
commit
788c9709fb
31
.local/bin/weather
Executable file
31
.local/bin/weather
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
WTTR_URL="${WTTR_URL:-wttr.in}"
|
||||||
|
REPORT_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/wttr-report"
|
||||||
|
UPDATE_INTERVAL_SECONDS=1800
|
||||||
|
|
||||||
|
notify() {
|
||||||
|
notify-send "${0##*/}" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_report_old() {
|
||||||
|
current_time="$(date +'%s')"
|
||||||
|
report_file_time="$(date -r "$REPORT_FILE" +'%s')"
|
||||||
|
[ "$((current_time - report_file_time))" -ge "$UPDATE_INTERVAL_SECONDS" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ ! -f "$REPORT_FILE" ] || is_report_old; then
|
||||||
|
curl -s "$WTTR_URL?format=%C\n%t\n" >"$REPORT_FILE"
|
||||||
|
notify "Fetched new weather report."
|
||||||
|
fi
|
||||||
|
|
||||||
|
i=0
|
||||||
|
while IFS= read -r line; do
|
||||||
|
case "$i" in
|
||||||
|
0) conditions="${line%[[:space:]]}" ;;
|
||||||
|
1) temperature="${line#+}" ;;
|
||||||
|
esac
|
||||||
|
i=$((i + 1))
|
||||||
|
done <"$REPORT_FILE"
|
||||||
|
|
||||||
|
printf '%s (%s)\n' "$conditions" "$temperature"
|
Loading…
Reference in a new issue