dotfiles/legacy/bin/weather_cached

17 lines
347 B
Plaintext
Raw Normal View History

2020-08-02 00:06:16 +00:00
#!/bin/sh
2021-11-15 01:50:45 +00:00
CACHE_FILE="$HOME/.cache/weather_cache"
if [ "$1" = "clear" ]; then
rm -f "$CACHE_FILE"
fi
CACHE_TIME="$(stat -f %m "$CACHE_FILE" 2>/dev/null)"
2020-08-02 00:06:16 +00:00
NOW_TIME=$(date +%s)
TIME_PASSED=$((NOW_TIME-CACHE_TIME))
2021-04-10 17:40:34 +00:00
if [ "$TIME_PASSED" -gt "1200" ]
2020-08-02 00:06:16 +00:00
then
2021-04-10 17:40:34 +00:00
curl -m 2 -s "wttr.in/$WEATHER_CITY?format=%c%t" > "$CACHE_FILE"
2020-08-02 00:06:16 +00:00
fi
2021-04-10 17:40:34 +00:00
cat "$CACHE_FILE"