dotfiles/bin/weather

42 lines
892 B
Plaintext
Raw Normal View History

2019-06-25 12:57:16 +01:00
#!/usr/bin/env bash
_check_date() {
mkdir -p ~/.config/dotfiles/.data
touch ~/.config/dotfiles/.data/weather_date
local old_date=`cat ~/.config/dotfiles/.data/weather_date`
local new_date=`date +%d/%m/%Y`
if [ "$new_date" != "$old_date" ]
then
echo 1
else
echo 0
fi
}
weather() {
curl wttr.in/$1
}
main() {
wget -q --tries=10 --timeout=20 --spider tforgione.fr > /dev/null
net=$?
if [ "$1" == "startup" ]
then
# On terminal opening, checks if network is available
if [ $net -eq 0 ] && [ `_check_date` -eq 1 ]
then
weather
date +%d/%m/%Y > ~/.config/dotfiles/.data/weather_date
fi
elif [ $net -eq 0 ]
then
weather $@
else
echo -e "\033[31;1mNetwork unavailable, please check your connexion or try again later.\033[0m"
fi
}
main $@