dotfiles/bin/weather

37 lines
985 B
Bash
Executable File

#!/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
return 1
else
return 0
fi
}
main() {
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
else
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
}
main $@