Adds a loop in weather script to get weather for several cities a once

This commit is contained in:
Thibault Blanc-Beyne 2022-05-08 18:32:36 +02:00
parent 6f63ce00ec
commit 76f6f09a67
1 changed files with 18 additions and 7 deletions

View File

@ -14,23 +14,34 @@ _check_date() {
fi
}
main() {
if [ "$1" == "startup" ]; then
_check_date
if [ $? -ne 0 ]; then
curl --retry 10 --connect-timeout 20 wttr.in 2>/dev/null
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
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
else
curl --retry 10 --connect-timeout 20 wttr.in 2>/dev/null
if [ $? -ne 0 ]; then
if [ $? -eq 0 ]; then
echo -e "\033[31;1mNetwork unavailable, please check your connexion or try again later.\033[0m"
fi
fi
}
main() {
if [ "$1" == "startup" ]; then
_check_date
if [ $? -ne 0 ]; then
weather_loop ${@:2}
fi
else
weather_loop $@
fi
}
main $@