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() {
|
2019-06-25 13:12:13 +01:00
|
|
|
wget -q --tries=10 --timeout=20 --spider https://tforgione.fr > /dev/null
|
2019-06-25 12:57:16 +01:00
|
|
|
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 $@
|