Created
May 10, 2022 19:35
-
-
Save acid-bong/18b5552e32e4eb3e404a5d3cb86cccc1 to your computer and use it in GitHub Desktop.
Custom weather (wttr.in) module for slstatus. The first script writes weather info into the temp file (hourly job for cron), the second one is ran by slstatus and reads the file (every 0.25s, cuz i like to update seconds in the status bar as well)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
printf "%s" "$(</tmp/wttr)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ru.wttr.in?format="%C,+%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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment