Ticket #11991: nws-alert-better-geocode-test.patch

File nws-alert-better-geocode-test.patch, 2.1 KB (added by bkuhn@…, 10 years ago)

nws-alert patch to remove state/leading 0's when testing against 'cap:geocode' field

  • mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl

    From fd55fb5682cce57e7b6c15c8131a14353955698f Mon Sep 17 00:00:00 2001
    From: "Bradley M. Kuhn" <bkuhn@ebb.org>
    Date: Sun, 29 Dec 2013 19:12:20 -0500
    Subject: Remove state/leading 0's when testing against 'cap:geocode' field in
     output data.
    
    I was getting errors like:
       Argument "NY075" isn't numeric in int at  ../mythtv/mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl line 125.
    
    I analyzed the data and saw that the {int $geo} was being used, which doesn't
    work here.  I added a change to remove the state and leading zeros from the
    geo, as that seems to match what the NOAA site sends back in the place where
    we are testing.
    ---
     .../mythweather/mythweather/scripts/us_nws/nws-alert.pl    |   12 +++++++-----
     1 file changed, 7 insertions(+), 5 deletions(-)
    
    diff --git a/mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl b/mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl
    index 2386b3f..496793c 100755
    a b sub getEffectiveWarnings { 
    119119    my $tz = new Date::Manip::TZ;
    120120
    121121    my @dates;
     122    $geo =~ s/^[A-Z]*0*//i if (defined $geo);
     123    # The geo value is not going have states or leading zeros in the output.
    122124    while ($alert = shift @$alerts) {
    123125        push @dates, $alert->{'updated'};
    124126        while ($info = shift @{$alert->{'entry'}}) {
    125             if ($info->{'cap:effective'} &&
    126                 Date_Cmp($date, $info->{'cap:effective'}) >= 0 &&
    127                 Date_Cmp($date, $info->{'cap:expires'}) < 0 &&
    128                 (!$geo || $info->{'cap:geocode'}{int $geo})) {
     127            if ($info->{'cap:effective'} and
     128                Date_Cmp($date, ParseDate($info->{'cap:effective'})) >= 0 and
     129                Date_Cmp($date, ParseDate($info->{'cap:expires'})) < 0 and
     130                ( (not defined $geo) or $info->{'cap:geocode'}{$geo})) {
    129131                push @results, $info;
    130             }
     132              }
    131133        }
    132134    }
    133135    if (scalar(@dates) > 1) {