-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateGif.sh
73 lines (63 loc) · 1.56 KB
/
generateGif.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
NUM_IMAGES=24
DIR_HASSIO=
LST_COMUNITY=(am sa ba cc pm ca ma ml mu vd se va ss za)
usage="$(basename "$0") [-h] [-c province] [-d dir] -o output_dir -- program for generating GIF from AEMET Rain Radar images
where:
-h show this help text
-c set province value (default: Madrid)
-d set temporary directory to download images (default: /tmp/img)
-o set output full path
provinces:
am Almería
sa Asturias
ba Barcelona
cc Cáceres
pm Illes Balears
ca Las Palmas
ma Madrid
ml Málaga
mu Murcia
vd Palencia
se Sevilla
va Valencia
ss Vizcaya
za Zaragoza
"
DIR_DOWNLOAD=/tmp/img
PROVINCE=ma
while getopts ':hc:d:o:' option; do
case "$option" in
h) echo "$usage"
exit
;;
c) PROVINCE=$OPTARG
;;
d) DIR_DOWNLOAD=$OPTARG
;;
o) DIR_HASSIO=$OPTARG
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
mkdir -p $DIR_DOWNLOAD
rm -f $DIR_DOWNLOAD/*
for (( i=1; i<=$NUM_IMAGES; i++ ))
do
time=`expr $i \* 10`
eval $(date -u +Y=%Y\;m=%m\;d=%d\;H=%H\;M=%M -d "$time min ago")
[[ "$M" < "10" ]] && M=00 # cater for octal clash
M=$(((M/10)*10))
((M==0)) && M=00 # the math returns 0, so make it 00
url=http://www.aemet.es/imagenes_d/eltiempo/observacion/radar/${Y}${m}${d}${H}${M}_r8${PROVINCE}.gif
wget -q -P $DIR_DOWNLOAD $url
done
convert -delay 100 -loop 0 $DIR_DOWNLOAD/*.gif $DIR_HASSIO/radar_rain.gif