-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaf.sh
198 lines (159 loc) · 5.41 KB
/
taf.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
init(){
if [ -d "./taf" ]; then
rm -f ./taf/*
rmdir ./taf
fi
echo "Initialisation effectuee";
}
dlTafPays(){
if [ ! -d "./taf" ]; then
mkdir "./taf"
fi
if [ -f "./taf/$1-text.txt" -a -f "./taf/$1.txt" ]; then
echo "Fichiers deja telecharges"
else
curl "http://wx.rrwx.com/taf-$1.htm" > "./taf/$1.txt"
curl "http://wx.rrwx.com/taf-$1-txt.htm" > "./taf/$1-text.txt"
echo "Telechargement termine"
fi
}
extractTaf(){
if [ -f "./taf/$1-text.txt" -a -f "./taf/$1.txt" ]; then
aerop=`grep -i "$2" < "./taf/$1.txt" | awk -F "<b>" '{print $2}' | cut -d "<" -f1`
if [ ! -z "$aerop" ]; then
grep "$aerop" < "./taf/$1-text.txt" > "./taf/taf.txt"
fi
else
echo "Fichiers non trouvees"
fi
}
analyse(){
echo "Analyse et generation du rapport en cours..."
codeSource="<!DOCTYPE html><html><head><title>TAF</title></head><body><h2>TAF</h2><ul>"
mois=`date "+%m"`
tafTemp=$(cat "./taf/taf.txt")
set $tafTemp
echo "Analyse : $1" # Airport
airport="$1"
codeSource="$codeSource<li>Airport : $1</li>"
shift
if [ "$1" = "AMD" ]; then # in case of TAF AMD
echo "Analyse : $1"
shift
fi
echo "Analyse : $1" # Emitted
codeSource="$codeSource<li>Emitted : ${1:0:2}/$mois @ ${1:2:2}H${1:4:3}</li>"
shift
while [ ! -z "$1" ]; do
echo "Analyse : $1"
var="$1" #create var, and reset to "" when we catch it with a regex, to avoid that a second regex catch it
if [ ! `expr "$var" : '^\([+-]\{0,1\}[A-Z]\{2\}\{1,\}\)$'` = "" ]; then #Weather
codeSource="$codeSource<li>Weather : $1</li>"
var=""
fi
if [ ! `expr "$var" : '^\([0-9]\{4\}/[0-9]\{4\}\)$'` = "" ]; then #Periode
codeSource="$codeSource<li>Periode : ${1:0:2}/$mois @ ${1:2:2}H00Z .. ${1:5:2}/$mois @ ${1:7:2}H00Z</li>"
var=""
fi
if [ ! `expr "$var" : '^\([A-Z0-9]*KT\)$'` = "" ]; then #Wind
if [ "${1:5:1}" = "G" ]; then
codeSource="$codeSource<li>Wind : ${1:0:3} @ ${1:3:2} Gusting ${1:6:2} KT</li>"
else
codeSource="$codeSource<li>Wind : ${1:0:3} @ ${1:3:2} KT</li>"
fi
var=""
fi
if [ ! `expr "$var" : '^\([0-9]\{4\}\)$'` = "" ]; then #Horizontal visibility
if [ "$1" = "9999" ]; then
codeSource="$codeSource<li>Horizontal visibility > 10000 m</li>"
else
codeSource="$codeSource<li>Horizontal visibility : $1 m</li>"
fi
var=""
fi
if [ ! `expr "$var" : '^\([A-Z]\{3\}[0-9]\{3\}\)'` = "" ]; then #Clouds
typeClouds="${1:0:3}"
cloudsHauteur=`expr "${1:3:3}00" : '[0]\{0,2\}\([0-9]\{3,5\}\)'`
case "$typeClouds" in
"SKC") typeClouds="clear";;
"FEW") typeClouds="few";;
"SCT") typeClouds="scattered";;
"BKN") typeClouds="broken";;
"OVC") typeClouds="overcast";;
*) echo "$var : Type de nuage inconnu";;
esac
codeSource="$codeSource<li>Clouds : $typeClouds @ $cloudsHauteur ft</li>"
var=""
fi
if [ ! `expr "$var" : '^\(CAVOK\)$'` = "" ]; then #CAVOK
codeSource="$codeSource<li>Clouds : OK</li>"
var=""
fi
if [ ! `expr "$var" : '^\(TEMPO\)$'` = "" ]; then #TEMPO
codeSource="$codeSource</ul><h2>Temporary</h2><ul>"
var=""
fi
if [ ! `expr "$var" : '^\(BECMG\)$'` = "" ]; then #BECMG
codeSource="$codeSource</ul><h2>Becoming</h2><ul>"
var=""
fi
if [ ! `expr "$var" : '^PROB\([0-9]\{2\}\)$'` = "" ]; then #Probality
codeSource="$codeSource</ul><h2>Probality ${1:4:2}%</h2><ul>"
var=""
fi
shift
done
codeSource="$codeSource</ul></body></html>"
echo "$codeSource"> "./taf/taf-$airport.html"
echo "Analyse et generation du rapport termine"
if [ -f "./taf/buffer.txt" ]; then
rm -f ./taf/buffer.txt
fi
if [ -f "./taf/taf.txt" ]; then
rm -f ./taf/taf.txt
fi
}
run(){
dlTafPays $1
extractTaf $1 "$2"
analyse
}
multiple(){
run "$1" "$2"
echo `cat "./taf/taf-planDeVol.html" "./taf/taf-$airport.html"` > "./taf/taf-planDeVol.html"
if [ -f "./taf/taf-$airport.html" ]; then
rm -f "./taf/taf-$airport.html"
fi
}
initT(){
if [ ! -d "./taf" ]; then
mkdir "./taf"
fi
if [ -f "./taf/taf-planDeVol.html" ]; then
rm -f "./taf/taf-planDeVol.html"
fi
touch "./taf/taf-planDeVol.html"
}
while [ $# != 0 ]; do
case "$1" in
-i) init
shift;;
-d) dlTafPays $2
shift 2;;
-e) extractTaf $2 "$3"
shift 3;;
-a) analyse
shift;;
-p) run $2 "$3"
shift 3;;
-t) initT
while [ ! -z "$*" ]; do
if [ ! -z "$2" -a ! -z "$3" ]; then
multiple "$2" "$3"
fi
shift
shift
done;;
*) echo "Erreur" 1>&2 ;;
esac
done