Fix today execution when missing weather cache file
authorSiraaj Khandkar <siraaj@khandkar.net>
Wed, 27 Mar 2019 19:49:49 +0000 (15:49 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Wed, 27 Mar 2019 19:49:49 +0000 (15:49 -0400)
bin/today

index 74640e0..f9c2d28 100755 (executable)
--- 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 ''
This page took 0.027773 seconds and 4 git commands to generate.