Weathers checks network via wttr.in
This commit is contained in:
parent
20ff8248c0
commit
66df774356
37
bin/weather
37
bin/weather
|
@ -7,34 +7,29 @@ _check_date() {
|
||||||
local old_date=`cat ~/.config/dotfiles/.data/weather_date`
|
local old_date=`cat ~/.config/dotfiles/.data/weather_date`
|
||||||
local new_date=`date +%d/%m/%Y`
|
local new_date=`date +%d/%m/%Y`
|
||||||
|
|
||||||
if [ "$new_date" != "$old_date" ]
|
if [ "$new_date" != "$old_date" ]; then
|
||||||
then
|
return 1
|
||||||
echo 1
|
|
||||||
else
|
else
|
||||||
echo 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
weather() {
|
|
||||||
curl wttr.in/$1
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
wget -q --tries=10 --timeout=20 --spider https://tforgione.fr > /dev/null
|
if [ "$1" == "startup" ]; then
|
||||||
net=$?
|
_check_date
|
||||||
if [ "$1" == "startup" ]
|
if [ $? -ne 0 ]; then
|
||||||
then
|
curl --retry 10 --connect-timeout 20 wttr.in 2>/dev/null
|
||||||
# On terminal opening, checks if network is available
|
if [ $? -eq 0 ]; then
|
||||||
if [ $net -eq 0 ] && [ `_check_date` -eq 1 ]
|
date +%d/%m/%Y > ~/.config/dotfiles/.data/weather_date
|
||||||
then
|
else
|
||||||
weather
|
echo -e "\033[31;1mNetwork unavailable, please check your connexion or try again later.\033[0m"
|
||||||
date +%d/%m/%Y > ~/.config/dotfiles/.data/weather_date
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ $net -eq 0 ]
|
|
||||||
then
|
|
||||||
weather $@
|
|
||||||
else
|
else
|
||||||
echo -e "\033[31;1mNetwork unavailable, please check your connexion or try again later.\033[0m"
|
curl --retry 10 --connect-timeout 20 wttr.in 2>/dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "\033[31;1mNetwork unavailable, please check your connexion or try again later.\033[0m"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue