From c4fc77b8e6f99e195887049e2cb496c03ac99755 Mon Sep 17 00:00:00 2001 From: Thibault Blanc-Beyne Date: Tue, 25 Jun 2019 13:57:16 +0200 Subject: [PATCH] Adds weather script --- bin/weather | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 bin/weather diff --git a/bin/weather b/bin/weather new file mode 100755 index 0000000..f835247 --- /dev/null +++ b/bin/weather @@ -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 $@