From 66df7743561ec33750fdd9340470d4058bdb54f4 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 26 Jun 2019 09:20:43 +0200 Subject: [PATCH] Weathers checks network via wttr.in --- bin/weather | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/bin/weather b/bin/weather index 85ac672..21c1962 100755 --- a/bin/weather +++ b/bin/weather @@ -7,34 +7,29 @@ _check_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 + if [ "$new_date" != "$old_date" ]; then + return 1 else - echo 0 + return 0 fi } -weather() { - curl wttr.in/$1 -} - main() { - wget -q --tries=10 --timeout=20 --spider https://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 + if [ "$1" == "startup" ]; then + _check_date + if [ $? -ne 0 ]; then + curl --retry 10 --connect-timeout 20 wttr.in 2>/dev/null + if [ $? -eq 0 ]; then + date +%d/%m/%Y > ~/.config/dotfiles/.data/weather_date + else + echo -e "\033[31;1mNetwork unavailable, please check your connexion or try again later.\033[0m" + fi fi - elif [ $net -eq 0 ] - then - weather $@ 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 }