Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reworked all of the NOAA/NWS Weather Scripts

Seems weather.gov has moved the urls for nearly all their data services.  On
top of that, the SOAP response is gzip encoded by default, and SOAP::Lite is
stupid and can't handle it.  Also, we were missing the Units parameter which
is now required.

Fixes #10821
  • Loading branch information...
commit b8a78aeb35167a676a7e25c342a1869e8016d76a 1 parent 7bbcf8b
@Beirdo Beirdo authored
View
3  mythplugins/mythweather/mythweather/scripts/us_nws/NDFDParser.pm
@@ -177,7 +177,7 @@ sub timeChar {
########## Exported method to do parsing #################
sub doParse {
- my ($lat, $lon, $start, $end, $params) = @_;
+ my ($lat, $lon, $start, $end, $units, $params) = @_;
my $product = "time-series";
my $NDFD_XML = ndfdXML->NDFDgen(SOAP::Data->name("latitude" => $lat),
@@ -185,6 +185,7 @@ sub doParse {
SOAP::Data->name("product" => $product),
SOAP::Data->name("startTime" => $start),
SOAP::Data->name("endTime" => $end),
+ SOAP::Data->name("Unit" => $units),
SOAP::Data->name("weatherParameters" =>
\SOAP::Data->value(
SOAP::Data->type('boolean')->name("maxt" => $params->{maxt}),
View
17 mythplugins/mythweather/mythweather/scripts/us_nws/ndfd.pl
@@ -22,9 +22,9 @@
our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
my $name = 'NDFD-6_day';
-my $version = 0.3;
-my $author = 'Lucien Dunning';
-my $email = 'ldunning@gmail.com';
+my $version = 0.4;
+my $author = 'Gavin Hurlbut & Lucien Dunning';
+my $email = 'gjhurlbu@gmail.com';
my $updateTimeout = 15*60;
my $retrieveTimeout = 30;
my @types = ('3dlocation', '6dlocation', 'updatetime',
@@ -119,7 +119,8 @@
}
if ($getData) {
- ($result, $creationdate) = NDFDParser::doParse($latitude, $longitude, $d1, $d2, $param);
+ my $unit = ($units eq "SI" ? "m" : "e");
+ ($result, $creationdate) = NDFDParser::doParse($latitude, $longitude, $d1, $d2, $unit, $param);
# output cache
open(CACHE, ">$dir/ndfd_cache_${latitude}_${longitude}") or
die "cannot open cache ($dir/ndfd_cache_${latitude}_${longitude}) for writing";
@@ -171,17 +172,9 @@
}
my $geticon = 0;
if ($lowindex <= 5 && $result->{$time}->{temperature_minimum}) {
- if ($units eq 'SI') {
- $result->{$time}->{temperature_minimum} =
- int ( (5/9) * ($result->{$time}->{temperature_minimum}-32));
- }
print "low-${lowindex}::$result->{$time}->{temperature_minimum}\n";
$lowindex++;
} elsif ($hiindex <= 5 && $result->{$time}->{temperature_maximum}) {
- if ($units eq 'SI') {
- $result->{$time}->{temperature_maximum} =
- int ( (5/9) * ($result->{$time}->{temperature_maximum}-32));
- }
print "high-${hiindex}::$result->{$time}->{temperature_maximum}\n";
$hiindex++;
$geticon = 1;
View
13 mythplugins/mythweather/mythweather/scripts/us_nws/ndfd18.pl
@@ -18,9 +18,9 @@
our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
my $name = 'NDFD-18_Hour';
-my $version = 0.2;
-my $author = 'Lucien Dunning';
-my $email = 'ldunning@gmail.com';
+my $version = 0.3;
+my $author = 'Gavin Hurlbut & Lucien Dunning';
+my $email = 'gjhurlbu@gmail.com';
my $updateTimeout = 15*60;
my $retrieveTimeout = 30;
my @types = ('18hrlocation', 'updatetime',
@@ -116,7 +116,8 @@
}
if ($getData) {
- ($result, $creationdate) = NDFDParser::doParse($latitude, $longitude, $d1, $d2, $param);
+ my $unit = ($units eq "SI" ? "m" : "e");
+ ($result, $creationdate) = NDFDParser::doParse($latitude, $longitude, $d1, $d2, $unit, $param);
# output cache
open(CACHE, ">$dir/ndfd18_cache_${latitude}_${longitude}") or
die "cannot open cache ($dir/ndfd18_cache_${latitude}_${longitude}) for writing";
@@ -149,10 +150,6 @@
}
print "time-${index}::" . UnixDate($time, "%i %p\n");
- if ($units eq 'SI') {
- $result->{$time}->{temperature_hourly} =
- int( (5/9) * ($result->{$time}->{temperature_hourly}-32));
- }
print "temp-${index}::$result->{$time}->{temperature_hourly}\n";
print "pop-${index}::$pop12 %\n";
$icon = $result->{$time}->{'conditions-icon_forecast-NWS'};
View
24 mythplugins/mythweather/mythweather/scripts/us_nws/ndfdXML.pm
@@ -5,9 +5,9 @@ package ndfdXML;
my %methods = (
NDFDgenByDay => {
- endpoint => 'http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXMLserver.php',
- soapaction => 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDay',
- uri => 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl',
+ endpoint => 'http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php',
+ soapaction => 'http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDay',
+ uri => 'http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl',
parameters => [
SOAP::Data->new(name => 'latitude', type => 'xsd:decimal', attr => {}),
SOAP::Data->new(name => 'longitude', type => 'xsd:decimal', attr => {}),
@@ -17,15 +17,16 @@ my %methods = (
],
},
NDFDgen => {
- endpoint => 'http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXMLserver.php',
- soapaction => 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen',
- uri => 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl',
+ endpoint => 'http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php',
+ soapaction => 'http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen',
+ uri => 'http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl',
parameters => [
SOAP::Data->new(name => 'latitude', type => 'xsd:decimal', attr => {}),
SOAP::Data->new(name => 'longitude', type => 'xsd:decimal', attr => {}),
- SOAP::Data->new(name => 'product', type => 'typens:productType', attr => {}),
+ SOAP::Data->new(name => 'product', type => 'xsd:string', attr => {}),
SOAP::Data->new(name => 'startTime', type => 'xsd:dateTime', attr => {}),
SOAP::Data->new(name => 'endTime', type => 'xsd:dateTime', attr => {}),
+ SOAP::Data->new(name => 'Unit', type => 'xsd:string', attr => {}),
SOAP::Data->new(name => 'weatherParameters', type => 'typens:weatherParametersType', attr => {}),
],
},
@@ -50,15 +51,16 @@ for my $method (@EXPORT_OK) {
: (shift->self || __PACKAGE__->self(__PACKAGE__->new))
# function call, either get self or create new and assign to self
: (__PACKAGE__->self || __PACKAGE__->self(__PACKAGE__->new));
- $self->proxy($method{endpoint} || Carp::croak "No server address (proxy) specified") unless $self->proxy;
+ $self->proxy(($method{endpoint} || Carp::croak "No server address (proxy) specified"), options => {compress_threshold => 10000}) unless $self->proxy;
my @templates = @{$method{parameters}};
my $som = $self
-> endpoint($method{endpoint})
-> uri($method{uri})
-> on_action(sub{qq!"$method{soapaction}"!})
- -> call($method => map {@templates ? shift(@templates)->value($_) : $_} @_);
- UNIVERSAL::isa($som => 'SOAP::SOM') ? wantarray ? $som->paramsall : $som->result
- : $som;
+ -> call($method => map {@templates ? shift(@templates)->value($_) : $_} @_);
+
+ (UNIVERSAL::isa($som => 'SOAP::SOM') ?
+ (wantarray ? $som->paramsall : $som->result) : $som);
}
}
View
8 mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl 100644 → 100755
@@ -141,9 +141,9 @@ sub getEffectiveWarnings {
our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
my $name = 'NWS-Alerts';
-my $version = 0.3;
-my $author = 'Lucien Dunning';
-my $email = 'ldunning@gmail.com';
+my $version = 0.4;
+my $author = 'Gavin Hurlbut & Lucien Dunning';
+my $email = 'gjhurlbu@gmail.com';
my $updateTimeout = 10*60;
my $retrieveTimeout = 30;
my @types = ('swlocation', 'updatetime', 'alerts', 'copyright');
@@ -223,7 +223,7 @@ sub getEffectiveWarnings {
$updatetime = UnixDate($updatetime, "%b %d, %I:%M %p %Z");
print "updatetime::Last Updated at $updatetime\n";
-print "copyright::NOAA,National Weather Service\n";
+print "copyright::NOAA, National Weather Service\n";
sub doLocation {
my $code = shift;
View
12 mythplugins/mythweather/mythweather/scripts/us_nws/nwsxml.pl
@@ -18,9 +18,9 @@
our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
my $name = 'NWS-XML';
-my $version = 0.3;
-my $author = 'Lucien Dunning';
-my $email = 'ldunning@gmail.com';
+my $version = 0.4;
+my $author = 'Gavin Hurlbut & Lucien Dunning';
+my $email = 'gjhurlbu@gmail.com';
my $updateTimeout = 15*60;
my $retrieveTimeout = 30;
my @types = ('cclocation', 'station_id', 'latitude', 'longitude',
@@ -80,9 +80,9 @@
my $units = $opt_u;
-my $base_url = 'http://www.weather.gov/data/current_obs/';
-
-my $response = get $base_url . $loc . '.xml';
+my $base_url = 'http://w1.weather.gov/xml/current_obs/';
+my $url = $base_url . $loc . '.xml';
+my $response = get $url;
die unless defined $response;
my $xml = XMLin($response);
Please sign in to comment.
Something went wrong with that request. Please try again.