Subject: | Geo-WeatherNWS returns wrong (?) station code |
Date: | Sat, 9 Jun 2007 19:18:25 +0200 |
To: | bug-Geo-WeatherNWS [...] rt.cpan.org |
From: | Guenter Knauf <info [...] gknw.de> |
Hi Marc,
first thanks for your nice module!
When I was testing with it I came over a bunch of stations where a wrong code is returned;
this is because at the place where it gets set in WeatherNWS.pm is inside a loop, and if another 4-letter code appears in $Self->orbs then its set a second or third time, and is then not equal to the initial station code used for the lookup. This is bad because I would like to use the code inside the template to build up a link to the full report web site, and this then doesnt work.
Therefore I've patched WeatherNWS.pm and introduced a new var 'station' which returns the first occurence of the 4-letter code. I wasnt sure if you intended to populate the 'code' var with the last 4-letter code, and so I've just added 'station' so we have both...
Also I've addded a var 'time_sep' which returns the time separated with a colon which I also find useful for usage inside the template.
Finally I've fixed the URL to the ICAO lookup site since the old link seems not working.
Here's some samples to demonstrate the problem (the site runs already the patched version!):
http://svwe10.itex.at/perldemo/getweather.pl?station=yssy&debug=1
http://svwe10.itex.at/perldemo/getweather.pl?station=lowg&debug=1
there you see that the 'code' var differs from the 'station' var, and can see with 'orbs' why this happens. In addition you can here see another problem that the visibility is not present.
http://svwe10.itex.at/perldemo/getweather.pl?station=cywg&debug=1
this one seems to work correctly - 'code' and 'station' are equal, and visibility is present.
Here's my patch:
--- WeatherNWS.pm.orig Sun Feb 09 19:57:32 2003
+++ WeatherNWS.pm Sat Jun 09 17:49:05 2007
@@ -268,6 +268,9 @@
if (($Line =~ /^([A-Z][A-Z][A-Z][A-Z])/) && ($Line ne "AUTO"))
{
$Self->{code}="$Line";
+ if (!$Self->{station}) {
+ $Self->{station}="$Line";
+ }
}
#------------------------------------------------------------------------------
@@ -278,6 +281,7 @@
{
my $Timez=substr($Line,2,4);
$Self->{time}="$Timez";
+ $Self->{time_sep}=substr($Timez,0,2).":".substr($Timez,2,2);
$Self->{day}=substr($Line,0,2);
}
@@ -940,7 +944,7 @@
you end up having to re-code your parsing program. With the weather module,
all you need is a four-letter station code to get the most recent weather
observations. If you do not know what the station code is for your area,
- check the site at http://205.156.54.206/oso/siteloc.shtml to start your
+ check the site at https://pilotweb.nas.faa.gov/qryhtml/icao/ to start your
search.
Since this module uses the NWS METAR Observations, you can get weather
since I didnt dig yet that deep into this topic I currently dont know if the visibility is fixable.
thanks, Guenter.
--- WeatherNWS.pm.orig Sun Feb 09 19:57:32 2003
+++ WeatherNWS.pm Sat Jun 09 17:49:05 2007
@@ -268,6 +268,9 @@
if (($Line =~ /^([A-Z][A-Z][A-Z][A-Z])/) && ($Line ne "AUTO"))
{
$Self->{code}="$Line";
+ if (!$Self->{station}) {
+ $Self->{station}="$Line";
+ }
}
#------------------------------------------------------------------------------
@@ -278,6 +281,7 @@
{
my $Timez=substr($Line,2,4);
$Self->{time}="$Timez";
+ $Self->{time_sep}=substr($Timez,0,2).":".substr($Timez,2,2);
$Self->{day}=substr($Line,0,2);
}
@@ -940,7 +944,7 @@
you end up having to re-code your parsing program. With the weather module,
all you need is a four-letter station code to get the most recent weather
observations. If you do not know what the station code is for your area,
- check the site at http://205.156.54.206/oso/siteloc.shtml to start your
+ check the site at https://pilotweb.nas.faa.gov/qryhtml/icao/ to start your
search.
Since this module uses the NWS METAR Observations, you can get weather