-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.sh
executable file
·442 lines (332 loc) · 7.81 KB
/
weather.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/bin/bash
config="config.json"
# These are the requirements for the parse.
lat=$(jq -r '.required.latitude' $config)
long=$(jq -r '.required.longitude' $config)
api_key=$(jq -r '.required.api_key' $config)
units=$(jq -r '.units' $config)
# Script reads the config file to assign booleans.
city_value=$(jq -r '.display.city' $config)
if [ "$city_value" = "true" ]; then
display_city=true;
else
display_city=false;
fi
short_description_value=$(jq -r '.display.short_description' $config)
if [ "$short_description_value" = "true" ]; then
display_short_description=true;
else
display_short_description=false;
fi
description_value=$(jq -r '.display.description' $config)
if [ "$description_value" = "true" ]; then
display_description=true;
else
display_description=false;
fi
temp_value=$(jq -r '.display.temperature' $config)
if [ "$temp_value" = "true" ]; then
display_temp=true;
else
display_temp=false;
fi
feels_value=$(jq -r '.display.feels_like' $config)
if [ "$feels_value" = "true" ]; then
display_feel=true;
else
display_feel=false;
fi
pressure_value=$(jq -r '.display.pressure' $config)
if [ "$pressure_value" = "true" ]; then
display_pressure=true;
else
display_pressure=false;
fi
humidity_value=$(jq -r '.display.humidity' $config)
if [ "$humidity_value" = "true" ]; then
display_humidity=true;
else
display_humidity=false;
fi
wind_speed_value=$(jq -r '.display.wind.speed' $config)
if [ "$wind_speed_value" = "true" ]; then
display_wind_speed=true;
else
display_wind_speed=false;
fi
wind_direction_value=$(jq -r '.display.wind.direction' $config)
if [ "$wind_direction_value" = "true" ]; then
display_wind_direction=true;
else
display_wind_direction=false;
fi
rain_1h_value=$(jq -r '.display["rain.1h"]' $config)
if [ "$rain_1h_value" = "true" ]; then
display_rain_1h=true;
else
display_rain_1h=false;
fi
rain_3h_value=$(jq -r '.display["rain.3h"]' $config)
if [ "$rain_3h_value" = "true" ]; then
display_rain_3h=true;
else
display_rain_3h=false;
fi
snow_1h_value=$(jq -r '.display["snow.1h"]' $config)
if [ "$snow_1h_value" = "true" ]; then
display_snow_1h=true;
else
display_snow_1h=false;
fi
snow_3h_value=$(jq -r '.display["snow.3h"]' $config)
if [ "$snow_3h_value" = "true" ]; then
display_snow_3h=true;
else
display_snow_3h=false;
fi
# The section to read config file is over
#
# This section is to parse json from OpenWeather and assign values to variables
#
# Curl the desired location
database=".weather_data/data.json"
curl -ls "https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$long&appid=$api_key&units=$units" -o $database
if $display_city; then
echo -n "Weather in " && (jq -r '.name' $database)
fi
if $display_short_description; then
(jq -rj '.weather[0].main' $database)
fi
if $display_description; then
description=$(jq -rj '.weather[0].description' $database)
case $description in
# Thunderstorm
"thunderstorm with light rain")
echo "Thunderstorm with Light Rain"
;;
"thunderstorm with rain")
echo "Thunderstorm with Rain"
;;
"thunderstorm with heavy rain")
echo "Thunderstorm with Heavy Rain"
;;
"light thunderstorm")
echo "Light Thunderstorm"
;;
"thunderstorm")
echo "Thunderstorm"
;;
"heavy thunderstorm")
echo "Heavy Thunderstorm"
;;
"ragged thunderstorm")
echo "Ragged Thunderstorm"
;;
"thunderstorm with light drizzle")
echo "Thunderstorm with Light Drizzle"
;;
"thunderstorm with drizzle")
echo "Thunderstorm with Drizzle"
;;
"thunderstorm with heavy drizzle")
echo "Thunderstorm with Heavy Drizzle"
;;
# Drizzle
"light intensity drizzle")
echo "Light Intensity Drizzle"
;;
"drizzle")
echo "Drizzle"
;;
"heavy intensity drizzle")
echo "Heavy Intensity Drizzle"
;;
"light intensity drizzle rain")
echo "Light Intensity Drizzle Rain"
;;
"drizzle rain")
echo "Drizzle Rain"
;;
"heavy intensity drizzle rain")
echo "Heavy Intensity Drizzle Rain"
;;
"shower rain and drizzle")
echo "Shower Rain and Drizzle"
;;
"heavy shower rain and drizzle")
echo "Heavy Shower Rain and Drizzle"
;;
"shower drizzle")
echo "Shower Drizzle"
;;
# Rain
"light rain")
echo "Light Rain"
;;
"moderate rain")
echo "Moderate Rain"
;;
"heavy intensity rain")
echo "Heavy Intensity Rain"
;;
"very heavy rain")
echo "Very Heavy Rain"
;;
"extreme rain")
echo "Extreme Rain"
;;
"freezing rain")
echo "Freezing Rain"
;;
"light intensity shower rain")
echo "Light Intensity Shower Rain"
;;
"shower rain")
echo "Shower Rain"
;;
"heavy intensity shower rain")
echo "Heavy Intensity Shower Rain"
;;
"ragged shower rain")
echo "Ragged Shower Rain"
;;
# Snow
"light snow")
echo "Light Snow"
;;
"snow")
echo "Snow"
;;
"heavy snow")
echo "Heavy Snow"
;;
"sleet")
echo "Sleet"
;;
"light shower sleet")
echo "Light Shower Sleet"
;;
"shower sleet")
echo "Shower Sleet"
;;
"light rain and snow")
echo "Light Rain and Snow"
;;
"rain and snow")
echo "Rain and Snow"
;;
"light shower snow")
echo "Light Shower Snow"
;;
"shower snow")
echo "Shower Snow "
;;
"heavy shower snow")
echo "Heavy Shower Snow "
;;
# Atmosphere
"mist")
echo "Mist"
;;
"smoke")
echo "Smoke"
;;
"haze")
echo "Haze"
;;
"sand/dust whirls")
echo "Sand/Dust Whirls"
;;
"fog")
echo "Fog"
;;
"sand")
echo "Sand"
;;
"dust")
echo "Dust"
;;
"volcanic ash")
echo "Volcanic Ash"
;;
"squalls")
echo "Squalls"
;;
"tornado")
echo "Tornado"
;;
"clear sky")
echo "Clear Sky"
;;
# Clouds
"few clouds")
echo "Few Clouds"
;;
"scattered clouds")
echo "Scattered Clouds"
;;
"broken clouds")
echo "Broken Clouds"
;;
"overcast clouds")
echo "Overcast Clouds"
;;
esac
fi
if $display_temp; then
case $units in
"standart")
(jq -rj '.main.temp' $database) && echo " Kelvin"
;;
"metric")
(jq -rj '.main.temp' $database) && echo " °C"
;;
"imperial")
(jq -rj '.main.temp' $database) && echo " °F"
;;
esac
fi
if $display_feel; then
case $units in
"standart")
echo -n "Feels like " && (jq -rj '.main.feels_like' $database) && echo " Kelvin"
;;
"metric")
echo -n "Feels like " && (jq -rj '.main.feels_like' $database) && echo " °C"
;;
"imperial")
echo -n "Feels like " && (jq -rj '.main.feels_like' $database) && echo " °F"
;;
esac
fi
if $display_pressure; then
(jq -rj '.main.pressure' $database) && echo " Pascal pressure"
fi
if $display_humidity; then
(jq -rj '.main.humidity' $database) && echo " % humidity"
fi
if $display_wind_speed; then
case $units in
"standart"|"metric")
echo -n "Wind speed is " && (jq -rj '.wind.speed' $database) && echo " km/h"
;;
"imperial")
echo -n "Wind speed is " && (jq -rj '.wind.speed' $database) && echo " mph"
;;
esac
fi
if $display_wind_direction; then
echo -n "Wind direction is " && (jq -rj '.wind.deg' $database) && echo " degree"
fi
if $display_rain_1h; then
echo -n "Rain for the last 1 hour is " && (jq -rj '.rain.1h' $database) && echo " mm"
fi
if $display_rain_3h; then
echo -n "Rain for the last 3 hours is " && (jq -rj '.rain.3h' $database) && echo " mm"
fi
if $display_snow_1h; then
echo -n "Snow for the last 1 hour is " && (jq -rj '.snow.1h' $database) && echo " mm"
fi
if $display_snow_3h; then
echo -n "Snow for the last 3 hour is " && (jq -rj 'snow.3h' $database) && echo " mm"
fi