From: Siraaj Khandkar Date: Wed, 27 Mar 2019 19:49:49 +0000 (-0400) Subject: Fix today execution when missing weather cache file X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=e2aa45549711f4938f8863a265667a0413ec23b8;hp=d746703ea97b59dc14ed6f80e1908a774645f19a;p=khome.git Fix today execution when missing weather cache file --- 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 ''