Ticket #8356: script-fixes-1.patch

File script-fixes-1.patch, 4.5 KB (added by Alec leamas <gmail: leamas.alec>, 16 years ago)
  • mythweather/scripts/us_nws/nwsxml.pl

    Explores new behaviour to provide all available values without converting.
    
    From: Alec Leamas <leamas.alec@gmail.com>
    
    
    ---
    
     mythweather/scripts/us_nws/nwsxml.pl |   78 ++++++++++------------------------
     1 files changed, 23 insertions(+), 55 deletions(-)
    
    
    diff --git a/mythweather/scripts/us_nws/nwsxml.pl b/mythweather/scripts/us_nws/nwsxml.pl
    index ab82815..2e9cf82 100755
    a b my @types = ('cclocation', 'station_id', 'latitude', 'longitude',  
    2121        'wind_dir', 'wind_degrees', 'wind_speed', 'wind_gust',
    2222        'pressure_string', 'pressure', 'dewpoint_string', 'dewpoint',
    2323        'heat_index_string', 'heat_index', 'windchill_string', 'windchill',
    24         'visibility', 'weather_icon', 'appt', 'wind_spdgst', 'copyright');
     24        'visibility', 'weather_icon', 'appt', 'copyright');
    2525my $dir = "./";
    2626
    2727getopts('Tvtlu:d:');
    foreach (@types) {  
    8484    $label = $_;
    8585
    8686    if (/temp$/ || /dewpoint$/ || /heat_index$/ || /windchill$/) {
    87         $key = $_ . '_f' if $units =~ /ENG/;
    88         $key = $_ . '_c' if $units =~ /SI/;
     87        if (defined(  $xml->{$_ . '_c'})){
     88            printf( "%s::%s;%s\n",
     89                    $label, $xml->{$_ . '_c'}, $xml->{$_ . '_f'});
     90        }
    8991    }
    9092    elsif (/pressure$/) {
    91         $key = $_ . '_in' if $units =~ /ENG/;
    92         $key = $_ . '_mb' if $units =~ /SI/;
     93        printf( "%s::;%s\n", $label, $xml->{$_ . '_in'});
    9394    }
    9495    elsif (/wind_speed/) {
    95         if ($units =~ /ENG/) {
    96             $key = 'wind_mph';
    97         } else {
    98             $key = 'wind_kph';
    99             $xml->{$key} = int($xml->{'wind_mph'} * 1.609344 + .5);
    100         }
     96          printf( "%s::;%s\n", $label, $xml->{'wind_mph'});
    10197    } elsif (/wind_gust/) {
    10298        if (defined($xml->{'wind_gust_mph'})) {
    103             if ($units =~ /ENG/ || $xml->{'wind_gust_mph'} eq 'NA') {
    104                 $key = 'wind_gust_mph';
    105             } else {
    106                 $key = 'wind_gust_kph';
    107                 $xml->{$key} = int($xml->{'wind_gust_mph'} * 1.609344 + .5);
    108             }
     99            printf( "%s::;%s\n", $label, $xml->{'wind_gust_mph'});
     100            printf( "wind_spdgst::;%s\n", $xml->{'wind_gust_mph'});
     101
    109102        } else {
    110             $xml->{'wind_gust_mph'} = 'NA';
    111             $xml->{'wind_gust_kph'} = 'NA';
    112             $key = 'wind_gust';
     103            print "wind_gust::NA\n";
     104            print "wind_spdgst::NA\n"
    113105        }
    114106    } elsif (/visibility/) {
    115         if ($units =~ /ENG/) {
    116             $key = 'visibility_mi';
    117         } else {
    118             $key = 'visibility_km';
    119             $xml->{$key} = int($xml->{'visibility_mi'} * 1.609344 + .5);
    120         }
     107        printf( "%s::;%s\n", $label,  $xml->{'visibility_mi'});
    121108    } elsif (/weather_icon/) {
    122109        $key = 'weather_icon';
    123110        $xml->{$key} = 'unknown.png';
    foreach (@types) {  
    132119            }
    133120        }
    134121    } elsif (/cclocation/) {
    135         $key = 'location';   
     122         print "${label}::" . $xml->{'location'};
    136123    } elsif (/appt$/) {
    137124        if (defined($xml->{windchill_f})) {
    138             if ($xml->{windchill_f} eq 'NA') {
    139                 $key = 'heat_index_f' if ($units =~ /ENG/);
    140                 $key = 'heat_index_c' if ($units =~ /SI/);
    141             } else {
    142                 $key = 'windchill_f' if ($units =~ /ENG/);
    143                 $key = 'windchill_c' if ($units =~ /SI/);
    144             };
    145         } else {
    146             $key = 'appt';
    147         }
    148     } elsif (/wind_spdgst/) {
    149         # relying on this being after speed and gust
    150         $key = "wind_spdgst";
    151         if ($units =~ /ENG/ ) {
    152             $xml->{$key} = "$xml->{wind_mph} ($xml->{wind_gust_mph}) mph";
    153         } else {
    154             $xml->{$key} = "$xml->{wind_kph} ($xml->{wind_gust_kph}) kph";
     125            printf( "%s::%s;%s\n",
     126                    $label, $xml->{windchill_c}, $xml->{windchill_f});
     127       
     128        } elsif (defined($xml->{appt_f})) {
     129             printf( "%s::%s;%s\n",
     130                     $label, $xml->{appt_c}, $xml->{appt_f});
    155131        }
    156132    } elsif (/copyright/) {
    157         $key = "copyright";
    158         $xml->{$key} = $xml->{credit};
    159     } else {
    160         $key = $label;
    161     }
    162 
    163     print $label . "::";
    164     if (defined($xml->{$key})) {
    165         print $xml->{$key};
     133        print "copyright::$xml->{credit}\n";
    166134    } else {
    167         print "NA";
     135        my $value = (defined( $xml->{$_}) ? $xml->{$_} : "NA");
     136        print( "${label}::${value}\n");
    168137    }
    169     print "\n";
    170138}