Skip to content

Instantly share code, notes, and snippets.

@acid-bong
Created May 10, 2022 19:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acid-bong/18b5552e32e4eb3e404a5d3cb86cccc1 to your computer and use it in GitHub Desktop.
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)
#!/bin/bash
printf "%s" "$(</tmp/wttr)"
#!/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