diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-08-13 09:59:43 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-08-13 09:59:43 -0300 |
commit | dfee4c5d3f0738f16f8de5075b8dcd812fbbd62c (patch) | |
tree | 03b9226c077755dd304d04caada50eb8cc85c83b /weather-forecast | |
parent | f3c8ed6ea3bffbf81ec21203a7004a794a10262e (diff) | |
download | scripts-dfee4c5d3f0738f16f8de5075b8dcd812fbbd62c.tar.gz scripts-dfee4c5d3f0738f16f8de5075b8dcd812fbbd62c.tar.bz2 |
Adds weather-forecast
Diffstat (limited to 'weather-forecast')
-rwxr-xr-x | weather-forecast | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/weather-forecast b/weather-forecast new file mode 100755 index 0000000..269f740 --- /dev/null +++ b/weather-forecast @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Simple wrapper around wttr.in +# + +# Parameters +BASENAME="`basename $0`" +PROGRAM="$1" +CACHE="$HOME/.local/share/weather" + +# Load config +source $HOME/.custom/wttr.in.conf || exit 1 + +# weather-forecast service query +function weather_forecast_query { + # Make sure everything we need exists + mkdir -p $CACHE + touch $CACHE/weather-forecast.cur $CACHE/weather-forecast.prev + + # Save the previous forecast + cp $CACHE/weather-forecast.cur $CACHE/weather-forecast.prev + curl wttr.in/$LOCATION > $CACHE/weather-forecast.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-forecast.cur" ]; then + cp $CACHE/weather-forecast.prev $CACHE/weather-forecast.cur + fi + + # Display output + cat $CACHE/weather-forecast.cur +} + +# Main +weather_forecast_query |