From: Silvio Rhatto Date: Sat, 13 Aug 2016 12:59:43 +0000 (-0300) Subject: Adds weather-forecast X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=dfee4c5d3f0738f16f8de5075b8dcd812fbbd62c;p=scripts.git Adds weather-forecast --- diff --git a/TODO.md b/TODO.md index 8d77002..c1af5e5 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ TODO ==== +* Weather and weather-forecast: fetch new data only if current one is too old. * Better sandbox template * Should be indepotent. * Should work for more use cases. 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