tforecast_alert.sh - nws-forecast-mailer - fetch and deliver the NWS 48-hour forecast by email
(HTM) git clone git://src.adamsgaard.dk/nws-forecast-mailer
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
tforecast_alert.sh (1112B)
---
1 #!/bin/bash
2 recipient=("andersd@riseup.net")
3 latitude=40.330
4 longitude=-74.5647
5
6 function fetch {
7 curl --location --silent \
8 "http://f1.weather.gov/MapClick.php?w0=t&w1=td&w2=wc&w3=sfcwind&w3u=3&w4=sky&w5=pop&w6=rh&w7=rain&w8=thunder&w9=snow&w10=fzg&w11=sleet&w12=fog&w13u=0&w16u=1&w17u=1&AheadHour=0&Submit=Submit&FcstType=digital&textField1=${1}&textField2=${2}&site=all&unit=0&dd=&bw=&menu=1"|\
9 w3m -T text/html | cat -
10 }
11
12 out=$(fetch $latitude $longitude)
13
14 # any fog in the next 48 hours?
15 keyword="Fog"
16 if echo "$out" | grep "^$keyword" | grep '[A-Z]' >/dev/null; then
17
18 message=$(cat <<-END
19 Next 24 hours:
20 $(echo "$out" | grep "^Hour (EST)" | head -n 1)
21 $(echo "$out" | grep "^$keyword" | head -n 1)
22
23 Following 24 hours:
24 $(echo "$out" | grep "^Hour (EST)" | tail -n 1)
25 $(echo "$out" | grep "^$keyword" | tail -n 1)
26 END
27 )
28
29
30 for i in "${recipient[@]}"; do
31 echo "$message" | \
32 mutt -F muttrc \
33 -s "$keyword at ($latitude,$longitude) within the next 48 hours" \
34 -- $i
35 done
36
37 else
38 echo "No $keyword predicted within the next 48 hours"
39 fi