|
8 | 8 |
|
9 | 9 | # Last Updated:
|
10 | 10 | # 20131224 - USGS adjusted the URL due to a security vulnerability
|
| 11 | +# 20190828 - USGS now using https:// |
11 | 12 |
|
12 | 13 | ####################
|
13 | 14 | ## to make requests of specific site numbers and email if the water is up
|
|
22 | 23 | ## comma-delimited list of other people to send mail when the water is up
|
23 | 24 | ## mh.ini: USGS_Temp = minimum temperature your friends are willing to go kayaking
|
24 | 25 | ## mh.ini: weather_use_internet = 1
|
25 |
| -# Note that this uses the outside temp. If you don't have a weather station set up, you need to be using |
26 |
| -# weather_use_internet=1 in mh.private.ini, have internet_weather enabled, and have all of that working |
| 26 | +# Note that this uses the outside temp. If you don't have a weather station set up, you need to be using |
| 27 | +# weather_use_internet=1 in mh.private.ini, have internet_weather enabled, and have all of that working |
27 | 28 | # correctly.
|
28 |
| -#################### |
| 29 | +#################### |
29 | 30 |
|
30 |
| -my $USGS_URL; # The URL to build the request to the USGS |
31 |
| -my %USGS_Notify; # The River level to send notification |
32 |
| -my %USGS_Level; # The current River Level |
33 |
| -my %USGS_Name; # The River Name/Location |
| 31 | +my $USGS_URL; # The URL to build the request to the USGS |
| 32 | +my %USGS_Notify; # The River level to send notification |
| 33 | +my %USGS_Level; # The current River Level |
| 34 | +my %USGS_Name; # The River Name/Location |
34 | 35 |
|
35 |
| -my @MH_Rivers = split( / /, $config_parms{USGS_Monitor} ); # The River IDs and Notification level |
| 36 | +my @MH_Rivers = split(/ /,$config_parms{USGS_Monitor}); # The River IDs and Notification level |
36 | 37 |
|
37 | 38 | my $f_USGS_list = "$config_parms{data_dir}/web/USGS.txt";
|
38 | 39 | my $f_USGS_html = "$config_parms{data_dir}/web/USGS.html";
|
39 | 40 |
|
40 | 41 | # noloop=start
|
41 | 42 |
|
42 | 43 | # Build the URL
|
43 |
| -$USGS_URL = "http://waterdata.usgs.gov/nwis/current?multiple_site_no="; |
| 44 | +$USGS_URL = "https://waterdata.usgs.gov/nwis/current?multiple_site_no="; |
44 | 45 |
|
45 | 46 | #Add all of the rivers
|
46 |
| -for ( my $i = 0; $i <= @MH_Rivers; $i += 2 ) { |
47 |
| - $USGS_URL .= @MH_Rivers[$i] . "%2C"; |
48 |
| - $USGS_Notify{"@MH_Rivers[$i]"} = @MH_Rivers[ $i + 1 ]; |
| 47 | +for (my $i = 0; $i <= @MH_Rivers; $i+=2) { |
| 48 | + $USGS_URL .= @MH_Rivers[$i] . "%2C"; |
| 49 | + $USGS_Notify{"@MH_Rivers[$i]"} = @MH_Rivers[$i+1]; |
49 | 50 | }
|
50 | 51 |
|
51 | 52 | #More of the general URL
|
52 |
| -$USGS_URL .= "&search_site_no_match_type=exact&index_pmcode_STATION_NM=1&index_pmcode_DATETIME=2"; |
53 |
| - |
| 53 | +$USGS_URL .= "&search_site_no_match_type=exact&index_pmcode_STATION_NM=1&index_pmcode_DATETIME=2"; |
54 | 54 | # Add whether CFS or Level
|
55 |
| -if ( $config_parms{USGS_Rate} ) { $USGS_URL .= "&index_pmcode_00065=3"; } |
56 |
| -else { $USGS_URL .= "&index_pmcode_00060=3"; } |
57 |
| - |
| 55 | +if ($config_parms{USGS_Rate}) { $USGS_URL .= "&index_pmcode_00065=3"; } |
| 56 | +else { $USGS_URL .= "&index_pmcode_00060=3"; } |
58 | 57 | # And the last of the URL
|
59 |
| -$USGS_URL .= |
60 |
| - "&sort_key=site_no&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&column_name=lat_va&column_name=long_va&column_name=state_cd&column_name=county_cd&column_name=alt_va&column_name=huc_cd&sort_key_2=site_no&html_table_group_key=NONE&format=rdb&rdb_compression=value&list_of_search_criteria=multiple_site_no%2Crealtime_parameter_selection"; |
| 58 | +$USGS_URL .= "&sort_key=site_no&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&column_name=lat_va&column_name=long_va&column_name=state_cd&column_name=county_cd&column_name=alt_va&column_name=huc_cd&sort_key_2=site_no&html_table_group_key=NONE&format=rdb&rdb_compression=value&list_of_search_criteria=multiple_site_no%2Crealtime_parameter_selection"; |
61 | 59 |
|
62 | 60 | # noloop=stop
|
63 | 61 |
|
64 |
| -$p_USGS_list = new Process_Item("get_url $USGS_URL $f_USGS_html"); |
| 62 | +$p_USGS_list = new Process_Item("get_url -ua $USGS_URL $f_USGS_html"); |
65 | 63 |
|
66 | 64 | #############################################
|
67 | 65 |
|
68 |
| -$v_USGS_list = new Voice_Cmd('[Get,Read,Show] water levels'); |
69 |
| -$v_USGS_list->set_info('This is the USGS Water Level for selected rivers.'); |
| 66 | +$v_USGS_list = new Voice_Cmd('[Get,Read,Show] water levels'); |
| 67 | +$v_USGS_list -> set_info('This is the USGS Water Level for selected rivers.'); |
70 | 68 |
|
71 | 69 | $state = said $v_USGS_list;
|
72 | 70 |
|
73 | 71 | #Check to see if there's anything in the file before speaking
|
74 | 72 | #speak (text => $f_USGS_list, display => 0) if ($state eq 'Read' && file_size $f_USGS_list);
|
75 |
| -if ( $state eq 'Read' ) { |
76 |
| - if ( file_size $f_USGS_list) { speak text => "app=usgs $f_USGS_list"; } |
77 |
| - else { speak text => 'app=usgs No water anywhere!'; } |
78 |
| -} |
79 |
| -elsif ( $state eq 'Show' ) { |
80 |
| - if ( file_size $f_USGS_list) { |
81 |
| - respond |
82 |
| - text => $f_USGS_list, |
83 |
| - time => 240, |
84 |
| - font => 'Times 25 bold', |
85 |
| - geometry => '+0+0', |
86 |
| - width => 36, |
87 |
| - height => 12; |
88 |
| - } |
89 |
| - else { |
90 |
| - respond |
91 |
| - text => 'No water anywhere!', |
92 |
| - time => 240, |
93 |
| - font => 'Times 25 bold', |
94 |
| - geometry => '+0+0', |
95 |
| - width => 36, |
96 |
| - height => 12; |
97 |
| - } |
98 |
| -} |
99 |
| -elsif ( $state eq 'Get' ) { |
100 |
| - |
| 73 | +if ($state eq 'Read') { |
| 74 | + if (file_size $f_USGS_list) { speak text => "app=usgs $f_USGS_list"; } else { speak text => 'app=usgs No water anywhere!';} |
| 75 | +} elsif ($state eq 'Show') { |
| 76 | + if (file_size $f_USGS_list) { respond text => $f_USGS_list, time => 240, font => 'Times 25 bold', geometry => '+0+0', width => 36, height => 12; } |
| 77 | + else { respond text => 'No water anywhere!', time => 240, font => 'Times 25 bold', geometry => '+0+0', width => 36, height => 12; } |
| 78 | +} elsif ($state eq 'Get') { |
101 | 79 | # Do this only if the file has not already been updated in the last hour
|
102 |
| - if ( -s $f_USGS_html > 10 |
103 |
| - and time_date_stamp( 3, $f_USGS_html ) eq time_date_stamp(3) ) |
104 |
| - { |
| 80 | + if (-s $f_USGS_html > 10 and |
| 81 | + time_date_stamp(3, $f_USGS_html) eq time_date_stamp(3)) { |
105 | 82 | print_log "USGS list is current";
|
106 |
| - |
107 |
| - # fixed 100219 looks like it spoke, then set things to read, and then read it again. |
108 |
| - #speak text => "app=usgs $f_USGS_list" if file_size $f_USGS_list; |
109 |
| - start $p_USGS_list 'do_nothing'; # Fire the process with no-op, so we can still run the parsing code for debug |
| 83 | + # fixed 100219 looks like it spoke, then set things to read, and then read it again. |
| 84 | + #speak text => "app=usgs $f_USGS_list" if file_size $f_USGS_list; |
| 85 | + start $p_USGS_list 'do_nothing'; # Fire the process with no-op, so we can still run the parsing code for debug |
110 | 86 | }
|
111 | 87 | else {
|
112 | 88 | if (&net_connect_check) {
|
113 | 89 | print_log "Retrieving USGS list from the net ...";
|
114 |
| - |
115 | 90 | # Use start instead of run so we can detect when it is done
|
116 | 91 | start $p_USGS_list;
|
117 | 92 | }
|
118 | 93 | else { speak "app=usgs Sorry, you must be logged onto the net"; }
|
119 |
| - } |
120 |
| - &respond_wait; # Tell web browser to wait for respond |
| 94 | + } |
| 95 | + &respond_wait; # Tell web browser to wait for respond |
121 | 96 | }
|
122 | 97 |
|
123 |
| -if ( done_now $p_USGS_list) { |
| 98 | +if (done_now $p_USGS_list) { |
124 | 99 | my $text = file_read $f_USGS_html;
|
125 | 100 |
|
126 | 101 | #To clean up the CGI USGS Site
|
127 | 102 | # clean up the top explanation
|
128 | 103 | $text =~ s/#.+#//s;
|
129 | 104 | print "Text1 = $text\n";
|
130 |
| - |
131 | 105 | #To clean up the table headers
|
132 | 106 | $text =~ s/^.+?(USGS)/$1/s;
|
133 | 107 |
|
134 | 108 | # Split out the values
|
135 |
| - my @USGS_RiverList = split( /\n/, $text ); |
136 |
| - my $USGS_River = ""; |
| 109 | + my @USGS_RiverList = split(/\n/,$text); |
| 110 | + my $USGS_River = ""; |
137 | 111 | my @USGS_RiverValues = ();
|
138 |
| - my $USGS_Message = ""; |
| 112 | + my $USGS_Message = ""; |
139 | 113 | foreach $USGS_River (@USGS_RiverList) {
|
140 |
| - @USGS_RiverValues = split( "\t", $USGS_River ); |
141 |
| - $USGS_Level{"@USGS_RiverValues[1]"} = @USGS_RiverValues[7]; |
142 |
| - $USGS_Name{"@USGS_RiverValues[1]"} = @USGS_RiverValues[2]; |
143 |
| - print "Result: " . $USGS_Level{"@USGS_RiverValues[1]"} . $USGS_Name{"@USGS_RiverValues[1]"} . "\n"; |
144 |
| - if ( ( $USGS_Level{"@USGS_RiverValues[1]"} >= $USGS_Notify{"@USGS_RiverValues[1]"} ) |
145 |
| - && $USGS_Level{"@USGS_RiverValues[1]"} ne "" ) |
146 |
| - { |
147 |
| - $USGS_Message .= $USGS_Name{"@USGS_RiverValues[1]"} . " is at " . $USGS_Level{"@USGS_RiverValues[1]"} . ".\n"; |
148 |
| - } |
| 114 | + @USGS_RiverValues = split("\t", $USGS_River); |
| 115 | + $USGS_Level{"@USGS_RiverValues[1]"} = @USGS_RiverValues[7]; |
| 116 | + $USGS_Name{"@USGS_RiverValues[1]"} = @USGS_RiverValues[2]; |
| 117 | + print "Result: " . $USGS_Level{"@USGS_RiverValues[1]"} . $USGS_Name{"@USGS_RiverValues[1]"} . "\n"; |
| 118 | + if (($USGS_Level{"@USGS_RiverValues[1]"} >= $USGS_Notify{"@USGS_RiverValues[1]"} ) && $USGS_Level{"@USGS_RiverValues[1]"} ne "") { |
| 119 | + $USGS_Message .= $USGS_Name{"@USGS_RiverValues[1]"} . " is at " . $USGS_Level{"@USGS_RiverValues[1]"} . ".\n"; |
| 120 | + } |
149 | 121 | }
|
150 |
| - |
151 | 122 | # Send mail if the rivers are up.
|
152 | 123 | if ($USGS_Message) {
|
153 |
| - print_log("Sending notification that rivers are up!"); |
154 |
| - |
155 |
| - # Notify friends that they need to go if it's warm enough! |
156 |
| - if ( ( $Weather{TempOutdoor} >= $config_parms{USGS_Temp} ) |
157 |
| - && ( $config_parms{USGS_Friends} ) ) |
158 |
| - { |
159 |
| - print_log("Notifying friends who need to know!"); |
160 |
| - &net_mail_send( |
161 |
| - subject => "Woohoo! Rivers are up", |
162 |
| - to => $config_parms{USGS_Friends}, |
163 |
| - text => $USGS_Message |
164 |
| - ); |
165 |
| - } |
166 |
| - else { # Email me anyway even if it's too cold |
167 |
| - $USGS_Message .= "Current temp is " . $Weather{TempOutdoor} . " degrees.\n"; |
168 |
| - &net_mail_send( |
169 |
| - subject => "Woohoo! Rivers are up", |
170 |
| - text => $USGS_Message |
171 |
| - ); |
172 |
| - } |
173 |
| - |
174 |
| - file_write( $f_USGS_list, $USGS_Message ); |
175 |
| - set $v_USGS_list 'Read'; |
176 |
| - } |
| 124 | + print_log ("Sending notification that rivers are up!"); |
| 125 | + # Notify friends that they need to go if it's warm enough! |
| 126 | + if (($Weather{TempOutdoor} >= $config_parms{USGS_Temp}) && ($config_parms{USGS_Friends})) { |
| 127 | + print_log ( "Notifying friends who need to know!"); |
| 128 | + &net_mail_send(subject => "Woohoo! Rivers are up", |
| 129 | + to => $config_parms{USGS_Friends}, |
| 130 | + text => $USGS_Message); |
| 131 | + } else { # Email me anyway even if it's too cold |
| 132 | + $USGS_Message .= "Current temp is " . $Weather{TempOutdoor} . " degrees.\n"; |
| 133 | + &net_mail_send(subject => "Woohoo! Rivers are up", |
| 134 | + text => $USGS_Message); |
| 135 | + } |
| 136 | + |
| 137 | + file_write($f_USGS_list, $USGS_Message); |
| 138 | + set $v_USGS_list 'Read'; |
| 139 | + } |
177 | 140 | }
|
178 | 141 |
|
179 | 142 | ###########################################################
|
|
186 | 149 | # 1.05 fixed so when there's nothing to report it doesn't try to talk.
|
187 | 150 | # 1.06 fixed for correct outside weather.
|
188 | 151 | # 1.07 Fixed logic error in how multiple notifications work
|
189 |
| -# 1.08 120611 Fixed from changes on the USGS site |
| 152 | +# 1.08 20120611 Fixed from changes on the USGS site |
| 153 | +# 1.09 20131224 USGS adjusted the URL due to a security vulnerability |
| 154 | +# 1.10 20190827 Added https support, as the USGS site went to only https 12/2018 |
0 commit comments