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`
|
|
|
|
|
2019-06-26 08:20:43 +01:00
|
|
|
if [ "$new_date" != "$old_date" ]; then
|
|
|
|
return 1
|
2019-06-25 12:57:16 +01:00
|
|
|
else
|
2019-06-26 08:20:43 +01:00
|
|
|
return 0
|
2019-06-25 12:57:16 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-08 17:32:36 +01:00
|
|
|
weather_loop() {
|
|
|
|
if [ $# -gt 0 ]
|
|
|
|
then
|
|
|
|
for ((i=1; i<=$#; i++)); do
|
|
|
|
curl --retry 10 --connect-timeout 20 wttr.in/${!i} 2>/dev/null
|
|
|
|
done
|
2019-06-26 08:20:43 +01:00
|
|
|
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
|
2019-06-25 12:57:16 +01:00
|
|
|
else
|
2019-06-26 08:20:43 +01:00
|
|
|
curl --retry 10 --connect-timeout 20 wttr.in 2>/dev/null
|
2022-05-08 17:32:36 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
2019-06-26 08:20:43 +01:00
|
|
|
echo -e "\033[31;1mNetwork unavailable, please check your connexion or try again later.\033[0m"
|
|
|
|
fi
|
2019-06-25 12:57:16 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-08 17:32:36 +01:00
|
|
|
main() {
|
|
|
|
if [ "$1" == "startup" ]; then
|
|
|
|
_check_date
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
weather_loop ${@:2}
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
weather_loop $@
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-25 12:57:16 +01:00
|
|
|
main $@
|