Adds weather script

This commit is contained in:
Thibault Blanc-Beyne 2019-06-25 13:57:16 +02:00
parent 36140e4265
commit c4fc77b8e6
1 changed files with 41 additions and 0 deletions

41
bin/weather Executable file
View File

@ -0,0 +1,41 @@
#!/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 $@