Files
dotfiles/slstatus/components/wttr.sh
T
2024-11-06 00:35:34 +07:00

28 lines
828 B
Bash
Executable File

#!/bin/bash
# This function checks if wttr.in is available before the weather info is fetched
ck_curl() {
curl -sf ru.wttr.in > /dev/null
}
ck_curl
if [ $? -eq 0 ] # $? means "output of the last command"
then
curl -s v2.wttr.in/tomsk?format="%t\n" > /tmp/wttr
wttr_net=1
else # Non-zero output would appear both when the site \
for (( cntr = 0; cntr < 3; cntr++ )) # is down and when you're physically offline
do
echo "Probing. " > /tmp/wttr
sleep 0.5
echo "Probing.. " > /tmp/wttr
sleep 0.5
echo "Probing..." > /tmp/wttr
sleep 0.5 # A wee bit of animation
done
ck_curl # Online check is rerun only once, if the first check fails.
fi # In case you're using wifi, and the cron job runs before \
# it authenticates
if ! [ $wttr_net ]
then echo "Offline fr :'( " > /tmp/wttr
fi