aboutsummaryrefslogtreecommitdiff
path: root/weather-query
blob: f8344157722d2175de3c719cef51673c122d1738 (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
37
38
39
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