home
/
code
/
khome.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
76db608
)
Cache weather report
author
Siraaj Khandkar
<siraaj@khandkar.net>
Mon, 25 Mar 2019 17:41:42 +0000
(13:41 -0400)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Mon, 25 Mar 2019 17:41:42 +0000
(13:41 -0400)
bin/today
patch
|
blob
|
blame
|
history
diff --git
a/bin/today
b/bin/today
index
0c7192a
..
74640e0
100755
(executable)
--- a/
bin/today
+++ b/
bin/today
@@
-1,7
+1,12
@@
-#! /bin/sh
+#! /bin/
ba
sh
set -e
set -e
+DIR_DATA="$HOME/var/run/today"
+FILE_WEATHER="$DIR_DATA/weather"
+
+mkdir -p "$DIR_DATA"
+
repeat() {
x="$1"
n="$2"
repeat() {
x="$1"
n="$2"
@@
-40,11
+45,21
@@
ip_addresses=$(
| column -t
)
| column -t
)
-weather=$(
- curl "http://wttr.in/${ZIP_CODE}?1" 2> /dev/null \
- || \
- echo "Weather update failed" \
-)
+weather_fetch() {
+ curl "http://wttr.in/${ZIP_CODE}?1" \
+ 1> "$FILE_WEATHER" \
+ 2> /dev/null
+}
+
+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 ]]
+ then
+ weather_fetch
+ fi
+ cat "$FILE_WEATHER"
+}
clear
#LANG="$ts_lang" ncal -M $(date +%Y)
clear
#LANG="$ts_lang" ncal -M $(date +%Y)
@@
-61,5
+76,6
@@
echo "$bar"
echo "$ip_addresses"
echo "$bar"
echo ''
echo "$ip_addresses"
echo "$bar"
echo ''
-echo "$weather"
+echo "Fetched on: $(stat -c %y $FILE_WEATHER)"
+echo "$(weather_get_or_fetch)"
echo ''
echo ''
This page took
0.027969 seconds
and
4
git commands to generate.