-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeteo1.script
322 lines (280 loc) · 5.83 KB
/
meteo1.script
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
shopt -s extglob
# options
# -C, --city Location city
# -r, --windchill Wind chill
# -D, --winddir Wind direction (degrees)
# -w, --windcomp Wind direction (compass)
# -W, --windspeed Wind speed
# -f, --feelslike Felt temperature
# -H, --humidity Atmosphere humidity
# -V, --visibiliy Visibility
# -p, --pressure Pressure
# -T, --text Current condition text
# -i, --icon Current condition icon
# -F, --font Current condition weather font
# -t, --temp Current temperature
# --day=n forecast
# where n can be 0,1,2,3
# and forecast can be
# day weekly day
# date day date
# low lowest temperature
# high highest temperature
# code forecast code
# text forecast text
# font forecast weather font
#
key=04dd9a3c9e0eeea2
location='ch/lausanne' #Losanna
#location='IT/alessano' # Corsano
#location='ITALY/sesto%20san%20giovanni' # Sesto San Giovanni
#location='ITALY/Ferrara'
#location='AT/Villach'
lang=IT
temp_dir=/tmp
temp_file_name=${location/\//_}
temp_file="$temp_dir"/"$temp_file_name"
url=http://api.wunderground.com/api/"$key"/conditions/lang:"$lang"/q/"$location".json
#url_10=http://api.wunderground.com/api/"$key"/forecast10day/onditions/q/"$location".json
#url='http://api.wunderground.com/api/92b68ee08d6be2ed/conditions/lang:IT/q/Italy/Sesto%20San%20Giovanni.json'
find "$temp_dir" -maxdepth 0 -name "$temp_file_name" -mmin -10 | egrep '.*' > /dev/null
# Test if temp has been modified more than 10 minutes ago.
# This is in order to avoid multiple download of the same file if more
# data are requested.
# | egrep '.*' serves the purpose to have an exit status not equal to 0
# when find has no match (it's an ugly hack, I know).
if [[ $? -ne 0 ]]; then
wget "$url" -O "$temp_file" -o /dev/null
fi
function Weather_Font {
case $1 in
@(*snow|*flurries) ) #snow
echo "r"
shift
;;
*rain* ) #rain
echo "j"
shift
;;
*storms* ) #tstorms
echo "l"
shift
;;
?(n)?(t)?(_)cloudy ) #cloudy
echo "e"
shift
;;
nt_mostlycloudy ) #mostly cloudy (night)
echo "D"
shift
;;
mostlycloudy ) #mostly cloudy (day)
echo "d"
shift
;;
nt_partlycloudy|nt_mostlysunny ) #partly cloudy (night)
echo "C"
shift
;;
partlycloudy|mostlysunny ) #partly cloudy (day)
echo "c"
shift
;;
@(*hazy|*fog) ) #foggy
echo "0"
shift
;;
nt_sunny ) #sunny (night....moony????)
echo "A"
shift
;;
sunny ) #sunny
echo "a"
shift
;;
nt_clear ) #clear (night)
echo "B"
shift
;;
clear ) #clear (day)
echo "b"
shift
;;
*sleet ) #sleet
shift
;;
esac
}
function Location_City {
jq -r '.current_observation.display_location.city' "$temp_file"
}
function Wind_Chill {
jq -r '.current_observation.windchill_c' "$temp_file"
}
function Wind_Direction_Degrees {
jq -r '.current_observation.wind_degrees' "$temp_file"
}
function Wind_Direction_Compass {
jq -r '.current_observation.wind_dir' "$temp_file"
}
function Wind_Speed {
jq -r '.current_observation.wind_kph' "$temp_file"
}
function Feel_Like {
jq -r '.current_observation.feelslike_c' "$temp_file"
}
function Humidity {
jq -r '.current_observation.relative_humidity' "$temp_file"
}
function Visibility {
jq -r '.current_observation.visibility_km' "$temp_file"
}
function Pressure {
jq -r '.current_observation.pressure_mb' "$temp_file"
}
function Current_Condition_Text {
jq -r '.current_observation.weather' "$temp_file"
}
function Current_Condition_Icon {
jq -r '.current_observation.icon' "$temp_file"
}
function Current_Temperature {
jq -r '.current_observation.temp_c' "$temp_file"
}
function Current_Icon {
jq -r '.current_observation.icon' "$temp_file"
}
function Day_n_Day {
row=$((44+$1))
awk -F"\042" 'NR=='''$row''' {print $2}' "$temp_file"
}
function Day_n_Date {
row=$((44+$1))
awk -F"\042" 'NR=='''$row''' {print $4}' "$temp_file"
}
function Day_n_Low {
row=$((44+$1))
awk -F"\042" 'NR=='''$row''' {print $6}' "$temp_file"
}
function Day_n_High {
row=$((44+$1))
awk -F"\042" 'NR=='''$row''' {print $8}' "$temp_file"
}
function Day_n_Condition_Text {
row=$((44+$1))
awk -F"\042" 'NR=='''$row''' {print $10}' "$temp_file"
}
function Day_n_Condition_Code {
row=$((44+$1))
awk -F"\042" 'NR=='''$row''' {print $12}' "$temp_file"
}
case "$1" in
-C|--city)
Location_City
shift
;;
-r|--windchill)
Wind_Chill
shift
;;
-D|--winddir)
Wind_Direction_Degrees
shift
;;
-w|--windcomp)
Wind_Direction_Compass
shift
;;
-W|--windspeed)
Wind_Speed
shift
;;
-f|--feelslike)
Feel_Like
shift
;;
-H|--humidity)
Humidity
shift
;;
-V|--visibility)
Visibility
shift
;;
-p|--pressure)
Pressure
shift
;;
-T|--text)
Current_Condition_Text
shift
;;
-i|--icon)
Current_Condition_Icon
shift
;;
-F|--font)
Weather_Font "$(Current_Icon)"
shift
;;
-t|--temp)
Current_Temperature
shift
;;
-a|--sunrise)
Sunrise
shift
;;
-z|--sunset)
Sunset
shift
;;
--day=*)
n=$(echo "$1" | sed 's/[^0-9]//g')
forecast="$2"
case "$forecast" in
day) #weekly day
Day_n_Day $n
shift
;;
date) #date day
Day_n_Date $n
shift
;;
low) #low temperature
Day_n_Low $n
shift
;;
high) #high temperature
Day_n_High $n
shift
;;
code) #forecast code
Day_n_Condition_Code $n
shift
;;
text) #forecast text
Day_n_Condition_text $n
shift
;;
font) #forecast weather font
Weather_Font "$(Day_n_Condition_Code $n)"
shift
;;
*)
# unknown option
;;
esac
# code forecast code
# cond forecast text
# font forecast weather fontWeather_Font
shift
;;
*)
# unknown option
;;
esac
# -t, --temp Current temperature
# -a, --sunrise Astronomy sunrise
# -z, --sunset Astronomy sunset