Adds weather script
This commit is contained in:
parent
36140e4265
commit
c4fc77b8e6
|
@ -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 $@
|
Loading…
Reference in New Issue