diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-08-20 21:01:26 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-08-20 21:01:26 -0300 |
commit | 827e804567b78eb7f8e2bdcfc1a9b77146992292 (patch) | |
tree | 4018a995ca186fdb457053816940ddc4cca05589 /weather-query | |
download | utils-weather-827e804567b78eb7f8e2bdcfc1a9b77146992292.tar.gz utils-weather-827e804567b78eb7f8e2bdcfc1a9b77146992292.tar.bz2 |
Initial importmain
Diffstat (limited to 'weather-query')
-rwxr-xr-x | weather-query | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/weather-query b/weather-query new file mode 100755 index 0000000..f834415 --- /dev/null +++ b/weather-query @@ -0,0 +1,40 @@ +#!/bin/bash +# +# 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 2> /dev/null + + # 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.prev $CACHE/weather.cur + fi + + # Display output + cat $CACHE/weather.cur +} + +# Main +if [ "$PROGRAM" == 'brweather' ]; then + brweather $* | grep -v 'Erro.' +else + weather_query +fi |