blob: 12a5d3a51519b7991e4a5a5e0ad91c5ebc3bf908 (
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
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
|
#!/bin/bash
# nws - a National Weather Service terminal client
# git.slickd.xyz/nws
source $HOME/.config/nws/nws.conf
version=v0.0.5
colors() {
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
}
cleanup() {
rm -rf ~/.cache/.county_ids ~/.cache/.weather_forecast ~/.cache/.weather_alerts /tmp/nws/ ~/.config/nws/cache/
}
save_json() {
if [ -z "${OUTPUT}" ];
then
echo You must specify an output directory.
exit
fi
echo -ne "Downloading files... (1 of 3)\r"
curl -s ipinfo.io>> "${OUTPUT}"/location.json
cords=$(jq -r '.loc' "${OUTPUT}"/location.json)
echo -ne "Downloading files... (2 of 3)\r"
curl -s https://api.weather.gov/points/$cords >> "${OUTPUT}"/weather.json
echo -ne "Downloading files... (3 of 3)\r"
curl -s https://api.weather.gov/alerts/active/zone/"${countyId}" >> "${OUTPUT}"/alerts.json
echo -e \n\nFinished
}
retrieve_counties() {
curl -s "https://api.weather.gov/zones?area=${state}" >> ~/.cache/.county_ids
colors
count=0
length=$(echo $(jq '.features | length' ~/.cache/.county_ids) -1 | bc)
while [ $count -le $length ]
do
echo -e ${GREEN}County: ${NOCOLOR}$(jq '.features['$count'].properties.name' ~/.cache/.county_ids)
echo -e ${GREEN}Id: ${NOCOLOR}$(jq '.features['$count'].properties.id' ~/.cache/.county_ids)
echo
((count++))
done
}
get_location() {
if [ ! -f ~/.config/nws/location.json ]; then
echo Downloading file
curl ipinfo.io >> ~/.config/nws/location.json
else
cords=$(jq -r '.loc' ~/.config/nws/location.json)
city=$(jq -r '.city' ~/.config/nws/location.json)
state=$(jq -r '.region' ~/.config/nws/location.json)
fi
}
show_radar() {
case $radar_choice in
"1") mpv --loop-file=inf "https://radar.weather.gov/ridge/standard/${area1}_loop.gif";;
"2") mpv --loop-file=inf "https://radar.weather.gov/ridge/standard/${area3}_loop.gif";;
"3") mpv --loop-file=inf "https://radar.weather.gov/ridge/standard/CONUS_loop.gif";;
*) echo "You can only choose from 1 to 3."
esac
}
show_alerts() {
colors
cleanup
curl -s "https://api.weather.gov/alerts/active/zone/${countyId}" >> ~/.cache/.weather_alerts
length=$(echo $(jq '.features | length' ~/.cache/.weather_alerts) -1 | bc)
count=0
while [ $count -le $length ]
do
echo
echo
echo --------------------------------------------------------------------------------------------------------------------------------------------
echo
echo -e ${GREEN}Alert: ${NOCOLOR}$(jq '.features['$count'].properties.headline' ~/.cache/.weather_alerts)
echo -e ${GREEN}Starts: ${NOCOLOR}$(jq '.features['$count'].properties.effective' ~/.cache/.weather_alerts)
echo -e ${GREEN}Ends: ${NOCOLOR}$(jq '.features['$count'].properties.expires' ~/.cache/.weather_alerts)
echo -e ${GREEN}Sent: ${NOCOLOR}$(jq '.features['$count'].properties.sent' ~/.cache/.weather_alerts)
echo -e ${GREEN}Severity: ${RED}$(jq '.features['$count'].properties.severity' ~/.cache/.weather_alerts)
echo -e ${NOCOLOR}
echo -e $(jq '.features['$count'].properties.parameters.NWSheadline' ~/.cache/.weather_alerts)
echo -e $(jq '.features['$count'].properties.description' ~/.cache/.weather_alerts)
echo -e $(jq '.features['$count'].properties.instruction' ~/.cache/.weather_alerts)
echo
echo -e ${GREEN}Affected areas: ${NOCOLOR}$(jq '.features['$count'].properties.areaDesc' ~/.cache/.weather_alerts)
echo -e ${GREEN}Wind: ${NOCOLOR}$(jq '.features['$count'].properties.windThreat' ~/.cache/.weather_alerts)
echo -e ${GREEN}Max Wind Gust: ${NOCOLOR}$(jq '.features['$count'].properties.maxWindGust' ~/.cache/.weather_alerts)
echo -e ${GREEN}Hail: ${NOCOLOR}$(jq '.features['$count'].properties.hailThreat' ~/.cache/.weather_alerts)
echo -e ${GREEN}Issued by $(jq '.features['$count'].properties.senderName' ~/.cache/.weather_alerts)${NOCOLOR}
echo --------------------------------------------------------------------------------------------------------------------------------------------
((count++))
done
echo
echo
((length++)) # json needs count to start at zero, real amount needs one added
echo -e ${GREEN}Total alerts: $length${NOCOLOR}
}
count_alerts() {
cleanup
curl -s "https://api.weather.gov/alerts/active/zone/${countyId}" >> ~/.cache/.weather_alerts
length=$(jq '.features | length' ~/.cache/.weather_alerts)
echo $length
}
show_spc() {
mpv --loop-file=inf "https://www.spc.noaa.gov/products/activity_loop.gif"
}
get_graphicast() {
mkdir -p ~/.config/nws/cache/
cleanup
count=1
prog=12.5
bar="#"
while [ $count -le 8 ]
do
wget -q -P ~/.config/nws/cache https://www.weather.gov/images/oun/graphicast/image${count}.png
echo -ne "(${prog}%) | ${bar} \r"
((count++))
prog=$(echo "$prog + 12.5" | bc)
bar="${bar}#"
done
echo "Getting Mesonet radar..."
wget -q -P ~/.config/nws/cache/ https://data.mesonet.org/data/nids/maps/realtime/${state_full}.MosaicBREF.png
$IV ~/.config/nws/cache/*
}
past_radar() {
colors
cleanup
count=0000
tick=0
mkdir -p ~/.config/nws/cache/past_radar/
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}0000.gif
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}0030.gif
until [ $tick -gt 3 ]
do
until [ $count -gt 930 ]
do
count=$(echo "$count + 30" | bc)
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}${tick}${count}.gif
count=$(echo "$count + 70" | bc)
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}${tick}${count}.gif
done
count=0000
((tick++))
done
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}2000.gif
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}2030.gif
tick=2
count=2100
until [ $count -gt 2330 ]
do
count=$(echo "$count + 30" | bc)
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}${count}.gif
count=$(echo "$count + 70" | bc)
wget -P ~/.config/nws/cache/past_radar/ https://www2.mmm.ucar.edu/imagearchive1/RadarComposites/${area4}/${date}/${area4}_${date}${count}.gif
done
# compiles into a video
convert -delay 40 -loop 1 ~/.config/nws/cache/past_radar/*gif ~/.config/nws/cache/past_radar/compiled.mp4
mpv --loop-file=inf ~/.config/nws/cache/past_radar/compiled.mp4
}
get_forecast() {
colors
cleanup
mkdir -p ~/.config/nws/cache/
get_location
curl -s $(curl -s https://api.weather.gov/points/$cords | jq -r .properties.forecast) >> ~/.cache/.weather_forecast
count=0
echo
length=$(echo $(jq '.properties.periods | length' ~/.cache/.weather_forecast) -1 | bc)
echo -e "Weather for ${GREEN}$city, $state${NOCOLOR}:"
echo
while [ $count -le $length ]
do
echo ----------------------------------------------------------------------------------------------------
echo -e ${GREEN}Day: ${NOCOLOR}$(jq '.properties.periods['$count'].name' ~/.cache/.weather_forecast)
echo -e ${GREEN}Temperature: ${NOCOLOR}$(jq '.properties.periods['$count'].temperature' ~/.cache/.weather_forecast)$(jq '.properties.periods['$count'].temperatureUnit' ~/.cache/.weather_forecast)
echo -e ${GREEN}Rain chance: ${NOCOLOR}$(jq '.properties.periods['$count'].probabilityOfPrecipitation.value' ~/.cache/.weather_forecast)%
echo -e ${GREEN}Wind: ${NOCOLOR}$(jq '.properties.periods['$count'].windDirection' ~/.cache/.weather_forecast), $(jq '.properties.periods['$count'].windSpeed' ~/.cache/.weather_forecast)
echo
echo $(jq '.properties.periods['$count'].detailedForecast' ~/.cache/.weather_forecast)
echo
echo ----------------------------------------------------------------------------------------------------
echo
echo
((count++))
done
echo ""
}
help() {
echo "nws $version"
echo
echo "Basic operations:"
echo
echo " -v: shows version"
echo " -f: shows local forecast"
echo " -a: shows weather alerts"
echo " --radar (1,2,3): shows local radar"
echo " --spc: shows storm predictions"
echo
echo
echo "Other operations:"
echo
echo " --retrieve-counties: shows county ids"
echo " --save-json: saves JSON files used to a directory"
echo " --ca: shows number of alerts"
echo " --gc: shows graphic forecast, uses image viewer set in config"
echo
}
radar_choice=$2
OUTPUT=$2
date=$2
case $1 in
'--past-radar') past_radar;;
'--radar') show_radar;;
'--spc') show_spc;;
'--retrieve-counties') retrieve_counties;;
'--save-json') save_json;;
'--ca') count_alerts;;
'--gc') get_graphicast;;
'-a') show_alerts | sed 's/null//g ; s/"//g' |less -R;;
'-f') get_forecast | sed 's/"//g ; s/null/0/g' | less -R;;
'-v') echo nws $version;;
'-h') help;;
'--help') help;;
"") help;;
esac
|