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',
|
| 21 | 21 | 'wind_dir', 'wind_degrees', 'wind_speed', 'wind_gust', |
| 22 | 22 | 'pressure_string', 'pressure', 'dewpoint_string', 'dewpoint', |
| 23 | 23 | 'heat_index_string', 'heat_index', 'windchill_string', 'windchill', |
| 24 | | 'visibility', 'weather_icon', 'appt', 'wind_spdgst', 'copyright'); |
| | 24 | 'visibility', 'weather_icon', 'appt', 'copyright'); |
| 25 | 25 | my $dir = "./"; |
| 26 | 26 | |
| 27 | 27 | getopts('Tvtlu:d:'); |
| … |
… |
foreach (@types) {
|
| 84 | 84 | $label = $_; |
| 85 | 85 | |
| 86 | 86 | 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 | } |
| 89 | 91 | } |
| 90 | 92 | elsif (/pressure$/) { |
| 91 | | $key = $_ . '_in' if $units =~ /ENG/; |
| 92 | | $key = $_ . '_mb' if $units =~ /SI/; |
| | 93 | printf( "%s::;%s\n", $label, $xml->{$_ . '_in'}); |
| 93 | 94 | } |
| 94 | 95 | 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'}); |
| 101 | 97 | } elsif (/wind_gust/) { |
| 102 | 98 | 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 | |
| 109 | 102 | } 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" |
| 113 | 105 | } |
| 114 | 106 | } 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'}); |
| 121 | 108 | } elsif (/weather_icon/) { |
| 122 | 109 | $key = 'weather_icon'; |
| 123 | 110 | $xml->{$key} = 'unknown.png'; |
| … |
… |
foreach (@types) {
|
| 132 | 119 | } |
| 133 | 120 | } |
| 134 | 121 | } elsif (/cclocation/) { |
| 135 | | $key = 'location'; |
| | 122 | print "${label}::" . $xml->{'location'}; |
| 136 | 123 | } elsif (/appt$/) { |
| 137 | 124 | 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}); |
| 155 | 131 | } |
| 156 | 132 | } 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"; |
| 166 | 134 | } else { |
| 167 | | print "NA"; |
| | 135 | my $value = (defined( $xml->{$_}) ? $xml->{$_} : "NA"); |
| | 136 | print( "${label}::${value}\n"); |
| 168 | 137 | } |
| 169 | | print "\n"; |
| 170 | 138 | } |