Skip to content

Instantly share code, notes, and snippets.

@titosemi
Created March 22, 2016 09:09
Show Gist options
  • Save titosemi/74c0b3e8f94a484d59a6 to your computer and use it in GitHub Desktop.
Save titosemi/74c0b3e8f94a484d59a6 to your computer and use it in GitHub Desktop.
Weather
# 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