Ticket #9799: nws-alert.pl.patch
File nws-alert.pl.patch, 2.9 KB (added by , 10 years ago) |
---|
-
nws-alert.pl.
old new 28 28 29 29 sub StartTag { 30 30 my ($expat, $name, %atts) = @_; 31 if ($name eq " cap:alert"){31 if ($name eq "feed"){ 32 32 $currAlert = {}; 33 33 } 34 34 35 if ($name eq " cap:info") {35 if ($name eq "entry") { 36 36 $currInfo = {}; 37 37 } 38 38 … … 42 42 sub EndTag { 43 43 my ($expat, $name, %atts) = @_; 44 44 45 if ($name eq " cap:alert") {45 if ($name eq "feed") { 46 46 push @$alerts, $currAlert; 47 47 } 48 if ($name eq " cap:info") {49 push (@{$currAlert->{' cap:info'}}, $currInfo);48 if ($name eq "entry") { 49 push (@{$currAlert->{'entry'}}, $currInfo); 50 50 } 51 51 } 52 52 53 53 sub Text { 54 54 my ($expat, $text) = @_; 55 55 56 if ($expat->within_element('cap:info')) { 56 if ($expat->within_element('cap:geocode') && $expat->within_element('value')) { 57 if($expat->{Text}) { 58 my %geocodes; 59 foreach my $geocode ($expat->{Text} =~ m/(\d+)/g) { 60 $geocodes{int $geocode} = 1; 61 } 62 $currInfo->{'cap:geocode'} = \%geocodes; 63 } 64 65 } elsif ($expat->within_element('entry')) { 57 66 $currInfo->{$expat->current_element} = $expat->{Text} if ($expat->{Text} 58 67 =~ /\w+/); 59 68 60 } elsif ($expat->within_element(' cap:alert')) {69 } elsif ($expat->within_element('feed')) { 61 70 $currAlert->{$expat->current_element} = $expat->{Text} if ($expat->{Text} =~ 62 71 /\w+/); 63 72 } … … 70 79 my $state = shift; 71 80 $state =~ tr/[A-Z]/[a-z]/; 72 81 my $parser = new XML::Parser(Style => 'Stream'); 73 my $capfile = get "http://www.weather.gov/alerts/$state. cap" or82 my $capfile = get "http://www.weather.gov/alerts/$state.php?x=0" or 74 83 die "cannot retrieve alert data"; 75 84 $parser->parse($capfile); 76 85 return $alerts; … … 94 103 95 104 my @dates; 96 105 while ($alert = shift @$alerts) { 97 push @dates, $alert->{' cap:sent'};98 while ($info = shift @{$alert->{' cap:info'}}) {106 push @dates, $alert->{'updated'}; 107 while ($info = shift @{$alert->{'entry'}}) { 99 108 if ($info->{'cap:effective'} && 100 Date_Cmp($date, "$info->{'cap:effective'}") >= 0 &&101 Date_Cmp($date, "$info->{'cap:expires'}") < 0 &&102 (!$geo || $info->{'cap:geocode'} == $geo)) {109 Date_Cmp($date, $info->{'cap:effective'}) >= 0 && 110 Date_Cmp($date, $info->{'cap:expires'}) < 0 && 111 (!$geo || $info->{'cap:geocode'}{int $geo})) { 103 112 push @results, $info; 104 113 } 105 114 } … … 182 191 my ($updatetime, @warnings) = getEffectiveWarnings("now", $state, $loc); 183 192 184 193 foreach my $warning (@warnings) { 185 my $txt = $warning->{' cap:description'};194 my $txt = $warning->{'summary'}; 186 195 for my $line (split /\n/, $txt) { 187 196 print "alerts::$line\n" if ($line =~ m/\w+/); 188 197 }