blob: 269f740b1068de21ef9004b3218795b3f1a0c482 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
|