aboutsummaryrefslogtreecommitdiff
path: root/weather-query
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2015-06-03 11:57:13 -0300
committerSilvio Rhatto <rhatto@riseup.net>2015-06-03 11:57:13 -0300
commit816e938e3cb2bf214a692deef47ce897d8748b26 (patch)
treea7b7bdc453fe759423d830b5af7239db7842fc13 /weather-query
parent5a60cdbccf81a116b3030656fd9eb7035fc106fe (diff)
downloadscripts-816e938e3cb2bf214a692deef47ce897d8748b26.tar.gz
scripts-816e938e3cb2bf214a692deef47ce897d8748b26.tar.bz2
Cache support at weather-query
Diffstat (limited to 'weather-query')
-rwxr-xr-xweather-query29
1 files changed, 28 insertions, 1 deletions
diff --git a/weather-query b/weather-query
index 774bb73..e925342 100755
--- a/weather-query
+++ b/weather-query
@@ -3,11 +3,38 @@
# Simple wrapper around brweather
#
+# Parameters
+BASENAME="`basename $0`"
PROGRAM="$1"
+CACHE="$HOME/.local/share/weather"
+
+# Command line args
shift
+# Weather service query
+function weather_query {
+ # Make sure everything we need exists
+ mkdir -p $CACHE
+ touch $CACHE/weather.cur $CACHE/weather.prev
+
+ # Save the previous forecast
+ cp $CACHE/weather.cur $CACHE/weather.prev
+ weather $* > $CACHE/weather.cur
+
+ # Test if current forecast is empty, meaning
+ # that we're probably ofline. In that case
+ # we provide the previous output.
+ if [ ! -s "$CACHE/weather.cur" ]; then
+ cp $CACHE/weather.pre $CACHE/weather.cur
+ fi
+
+ # Display output
+ cat $CACHE/weather.cur
+}
+
+# Main
if [ "$PROGRAM" == 'brweather' ]; then
brweather $* | grep -v 'Erro.'
else
- weather $*
+ weather_query
fi