Created
March 22, 2016 09:09
-
-
Save titosemi/74c0b3e8f94a484d59a6 to your computer and use it in GitHub Desktop.
Weather
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Weather | |
function weather() { | |
local cache_file='/tmp/weather.txt' | |
local cache=3600 | |
local update='false' | |
local modify='' | |
local now=$(date +%s) | |
local diff='' | |
if [[ ! -f "${cache_file}" ]]; then | |
update='true' | |
else | |
modify="$(stat -f "%m" "${cache_file}" 2>/dev/null)" | |
diff=$((now-modify)) | |
if [[ ${diff} -ge ${cache} ]]; then | |
update='true' | |
fi | |
fi | |
if [[ "${update}" == 'true' ]]; then | |
curl http://wttr.in/ > "${cache_file}" | |
fi | |
cat "${cache_file}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment