From e2aa45549711f4938f8863a265667a0413ec23b8 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Wed, 27 Mar 2019 15:49:49 -0400 Subject: [PATCH 1/1] Fix today execution when missing weather cache file --- bin/today | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/today b/bin/today index 74640e0..f9c2d28 100755 --- a/bin/today +++ b/bin/today @@ -51,16 +51,21 @@ weather_fetch() { 2> /dev/null } +weather_file_age() { + echo $(( $(date +%s) - $(stat -c '%Y' "$FILE_WEATHER") )) +} + weather_get_or_fetch() { - weather_file_age=$(( $(date +%s) - $(stat -c '%Y' "$FILE_WEATHER") )) weather_file_age_limit=$(( 3 * 60 * 60 )) - if [[ ! -e $FILE_WEATHER || $weather_file_age -ge $weather_file_age_limit ]] + if [[ ! -e $FILE_WEATHER || weather_file_age -ge $weather_file_age_limit ]] then weather_fetch fi cat "$FILE_WEATHER" } +weather="$(weather_get_or_fetch)" + clear #LANG="$ts_lang" ncal -M $(date +%Y) LANG="$ts_lang" ncal -M @@ -77,5 +82,5 @@ echo "$ip_addresses" echo "$bar" echo '' echo "Fetched on: $(stat -c %y $FILE_WEATHER)" -echo "$(weather_get_or_fetch)" +echo "$weather" echo '' -- 2.20.1