+weather_fetch() {
+ curl "http://wttr.in/${ZIP_CODE}?1" \
+ 1> "$FILE_WEATHER" \
+ 2> /dev/null
+}
+
+weather_file_age() {
+ echo $(( $(date +%s) - $(stat -c '%Y' "$FILE_WEATHER") ))
+}
+
+weather_get_or_fetch() {
+ weather_file_age_limit=$(( 3 * 60 * 60 ))
+ if [[ ! -e $FILE_WEATHER || weather_file_age -ge $weather_file_age_limit ]]
+ then
+ weather_fetch
+ fi
+ cat "$FILE_WEATHER"
+}
+
+weather="$(weather_get_or_fetch)"