Update weather.zsh to honor timeouts and try again later
This commit is contained in:
parent
b01add300c
commit
ff9a299f68
1 changed files with 18 additions and 11 deletions
|
@ -35,7 +35,7 @@ function weather_short_status() {
|
||||||
|
|
||||||
WEATHER_LOCATION_KEY="$(< "${HOME_LOCATION_KEY_PATH}")"
|
WEATHER_LOCATION_KEY="$(< "${HOME_LOCATION_KEY_PATH}")"
|
||||||
|
|
||||||
_weather_current_conditions | jq -r "$(<<'EOF'
|
_weather_current_conditions | jq -er "$(<<'EOF'
|
||||||
first |
|
first |
|
||||||
[
|
[
|
||||||
"RF:"+(.RealFeelTemperature.Imperial.Value | tostring)+"°",
|
"RF:"+(.RealFeelTemperature.Imperial.Value | tostring)+"°",
|
||||||
|
@ -49,7 +49,7 @@ first |
|
||||||
join(" ") |
|
join(" ") |
|
||||||
rtrimstr(" ")
|
rtrimstr(" ")
|
||||||
EOF
|
EOF
|
||||||
)"
|
)" 2>/dev/null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,15 +151,22 @@ function _weather_current_conditions() {
|
||||||
TEMP_OUTPUT="$(mktemp)"
|
TEMP_OUTPUT="$(mktemp)"
|
||||||
trap 'rm -f "${TEMP_OUTPUT}"' EXIT
|
trap 'rm -f "${TEMP_OUTPUT}"' EXIT
|
||||||
|
|
||||||
curl -LSsf \
|
(
|
||||||
--max-time "${WEATHER_CURL_TIMEOUT}" \
|
set +e
|
||||||
--get \
|
curl -LSsf \
|
||||||
-X GET \
|
--max-time "${WEATHER_CURL_TIMEOUT}" \
|
||||||
--data-urlencode "apikey=${WEATHER_API_KEY}" \
|
--get \
|
||||||
--data-urlencode "language=en-us" \
|
-X GET \
|
||||||
--data-urlencode "details=true" \
|
--data-urlencode "apikey=${WEATHER_API_KEY}" \
|
||||||
"https://dataservice.accuweather.com/currentconditions/v1/${WEATHER_LOCATION_KEY}" \
|
--data-urlencode "language=en-us" \
|
||||||
-o "${TEMP_OUTPUT}"
|
--data-urlencode "details=true" \
|
||||||
|
"https://dataservice.accuweather.com/currentconditions/v1/${WEATHER_LOCATION_KEY}" \
|
||||||
|
-o "${TEMP_OUTPUT}"
|
||||||
|
if [ $? -eq 28 ]; then
|
||||||
|
# timeout reached, just store empty data
|
||||||
|
echo '{}' > "${TEMP_OUTPUT}"
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
|
||||||
mv -f "${TEMP_OUTPUT}" "${CURRENT_WEATHER_CACHE_FILE}"
|
mv -f "${TEMP_OUTPUT}" "${CURRENT_WEATHER_CACHE_FILE}"
|
||||||
> /dev/stdout < "${CURRENT_WEATHER_CACHE_FILE}"
|
> /dev/stdout < "${CURRENT_WEATHER_CACHE_FILE}"
|
||||||
|
|
Loading…
Reference in a new issue