Skip Menu |
 

This queue is for tickets about the Geo-WeatherNWS CPAN distribution.

Report information
The Basics
Id: 27513
Status: resolved
Priority: 0/
Queue: Geo-WeatherNWS

People
Owner: BOBERNST [...] cpan.org
Requestors: info [...] gknw.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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>
Download (untitled) / with headers
text/plain 2.7k
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
Subject: [rt.cpan.org #27513] Geo-WeatherNWS returns wrong (?) station code
Date: Tue, 12 Jun 2007 12:26:58 +0200
To: bug-Geo-WeatherNWS [...] rt.cpan.org
From: Guenter Knauf <info [...] gknw.de>
Download (untitled) / with headers
text/plain 2.5k
Hi Marc, After some more testing with Geo-WeatherNWS I believe now that the problems with the code var I came over where a bunch of stations returned a wrong code was not intended; instead it seems to me that the regex was wrong since it also returned 5-character codes. In addition the regex didnt allow ICAO codes with numbers in it; so I changed now the regex to return only 4-character ICAO codes, and allow to have the last three also beeing numbers. Here're the old some samples again which show now that the 'code' and 'station' vars are equal: http://svwe10.itex.at/perldemo/getweather.pl?station=yssy&debug=1 http://svwe10.itex.at/perldemo/getweather.pl?station=lowg&debug=1 that're samples for ICAO codes containing numbers: http://svwe10.itex.at/perldemo/getweather.pl?station=k3a1&debug=1 http://svwe10.itex.at/perldemo/getweather.pl?station=k9f2&debug=1 Here's my new patch which includes also the patch to correct the new servername (#27515): --- WeatherNWS.pm.orig Mon Feb 10 03:57:32 2003 +++ WeatherNWS.pm Mon Jun 11 02:33:28 2007 @@ -36,7 +36,7 @@ my $Class=ref($Proto) || $Proto; my $Self={}; - $Self->{servername}="weather.noaa.gov"; + $Self->{servername}="tgftp.nws.noaa.gov"; $Self->{username}="anonymous"; $Self->{password}='weather@cpan.org'; $Self->{directory}="/data/observations/metar/stations"; @@ -265,9 +265,12 @@ foreach $Line (@Splitter) { - if (($Line =~ /^([A-Z][A-Z][A-Z][A-Z])/) && ($Line ne "AUTO")) + if (($Line =~ /^([A-Z][A-Z0-9]{3})$/) && ($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 for the moment I have still the 'station' var in, but I think now its probably not needed anymore; will test some more, and check if 'code' and 'station' are now always equal. thanks, Guenter.
Subject: [rt.cpan.org #27513] Geo-WeatherNWS returns wrong (?) station code
Date: Wed, 13 Jun 2007 20:34:19 +0200
To: bug-Geo-WeatherNWS [...] rt.cpan.org
From: Guenter Knauf <info [...] gknw.de>
Hi Marc, I did some more hacking around, and changed / fixed some regex, and added now 7 new vars, and finally prepared for a new release which I want to propose: - Fixed servername, fixed code var setting - added full date to obs var for http request - added vars windspeedkmh, windgustkmh, year, month, hour, minute, time_sep Here are the old samples which show now that the 'code' and 'station' vars are equal: http://svwe10.itex.at/perldemo/getweather.pl?station=yssy&debug=1 http://svwe10.itex.at/perldemo/getweather.pl?station=lowg&debug=1 that are samples for ICAO codes containing numbers: http://svwe10.itex.at/perldemo/getweather.pl?station=k3a1&debug=1 http://svwe10.itex.at/perldemo/getweather.pl?station=k9f2&debug=1 Here's my latest patch which includes also the patch to correct the new servername (#27515): --- WeatherNWS.pm.orig Mon Feb 10 03:57:32 2003 +++ WeatherNWS.pm Wed Jun 13 17:19:14 2007 @@ -6,6 +6,9 @@ # # Last Modified: 18 December 2001 - Prepared for CPAN - Marc Slagle # 24 February 2002 - Adding server/error code - Marc +# 13 June 2007 - Fixed servername, fixed code var setting +# - added vars year, month, hour, minute, +# time_sep, windspeedkmh, windgustkmh # #------------------------------------------------------------------------------ @@ -24,7 +27,7 @@ # Version #------------------------------------------------------------------------------ -our $VERSION = '1.03'; +our $VERSION = '1.04'; #------------------------------------------------------------------------------ # Lets create a new self @@ -36,7 +39,7 @@ my $Class=ref($Proto) || $Proto; my $Self={}; - $Self->{servername}="weather.noaa.gov"; + $Self->{servername}="tgftp.nws.noaa.gov"; $Self->{username}="anonymous"; $Self->{password}='weather@cpan.org'; $Self->{directory}="/data/observations/metar/stations"; @@ -123,7 +126,7 @@ { use LWP::UserAgent; my $Ua=LWP::UserAgent->new(); - $Ua->agent("Geo::WeatherNWS 1.03"); + $Ua->agent("Geo::WeatherNWS $VERSION"); my $Req=HTTP::Request->new(GET => "$Self->{http}"); $Req->content_type('application/x-www-form-urlencoded'); @@ -134,9 +137,13 @@ my @Lines=split(/\n/,$Res->content); foreach my $Line (@Lines) { - if ($Line =~ /^([A-Z][A-Z][A-Z][A-Z])/) + if ($Line =~ /^([0-9]{4}\/[0-9]{2}\/[0-9]{2}) [0-9]{2}:[0-9]{2}/) { - $Self->{obs}=$Line; + $Self->{obs}="$1 "; + } + if ($Line =~ /^[A-Z][A-Z0-9]{3} /) + { + $Self->{obs}.=$Line; last; } } @@ -265,20 +272,34 @@ foreach $Line (@Splitter) { - if (($Line =~ /^([A-Z][A-Z][A-Z][A-Z])/) && ($Line ne "AUTO")) + if (($Line =~ /^[A-Z][A-Z0-9]{3}$/) && ($Line ne "AUTO")) { - $Self->{code}="$Line"; + if (!$Self->{code}) { + $Self->{code}="$Line"; + } } #------------------------------------------------------------------------------ # Report Time #------------------------------------------------------------------------------ - elsif ($Line =~ /([0-9]Z)$/) + elsif ($Line =~ /([0-9]{2})([0-9]{2})([0-9]{2})Z$/) + { + $Self->{day}="$1"; + $Self->{hour}="$2"; + $Self->{minute}="$3"; + $Self->{time}="$2$3"; + $Self->{time_sep}="$2:$3"; + } + +#------------------------------------------------------------------------------ +# Report Date +#------------------------------------------------------------------------------ + + elsif ($Line =~ /^([0-9]{4})\/([0-9]{2})\/([0-9]{2})$/) { - my $Timez=substr($Line,2,4); - $Self->{time}="$Timez"; - $Self->{day}=substr($Line,0,2); + $Self->{year}="$1"; + $Self->{month}="$2"; } #------------------------------------------------------------------------------ @@ -362,13 +383,17 @@ } my $MPH=int($Windspeedkts/0.868391); + my $KMH=int($Windspeedkts*1.851984); my $GMPH=int($Windgustkts/0.868391); + my $GKMH=int($Windgustkts*1.851984); $Self->{windspeedkts}=$Windspeedkts; $Self->{windgustkts}=$Windgustkts; $Self->{windspeedkts}=$Self->{windspeedkts}-0; $Self->{windspeedmph}=$MPH; + $Self->{windspeedkmh}=$KMH; $Self->{windgustmph}=$GMPH; + $Self->{windgustkmh}=$GKMH; $Self->{winddirtext}=$Winddirtxt; $Self->{winddir}=$Winddir; $Self->{winddir}=$Self->{winddir}-0; @@ -902,6 +927,15 @@ =head1 DESCRIPTION + New for version 1.04: the regex was changed to enable also ICAO codes which + contain numbers. In addition the $Report{code} var now always gets set with + the first ICAO code returned; previous versions picked up codes at the end + of the ob line, and even 5-character codes which was wrong. + Added seven new vars: windspeedkmh, windgustkmh, year, month, hour, minute, + and time_sep which returns the time separated with a colon. + Also the returned obs from ftp and http request are now equal - with previous + version the full date was missing with http. + New for version 1.03: the getreporthttp call now calls the script on the weather.noaa.gov site for those who cant FTP through firewalls. @@ -940,7 +974,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 @@ -1006,10 +1040,12 @@ These are the returned values specific to wind: + $Report->{windspeedkmh} # Wind Speed (in kmh) $Report->{windspeedmph} # Wind Speed (in mph) $Report->{windspeedkts} # Wind Speed (in kts) $Report->{winddir} # Wind Direction (in degrees) $Report->{winddirtext} # Wind Direction (text version) + $Report->{windgustkmh} # Wind Gusts (kmh) $Report->{windgustmph} # Wind Gusts (mph) $Report->{windgustkts} # Wind Gusts (kts) attached a tar.gz archive which contains everything... thanks, Guenter.
Download Geo-WeatherNWS-1.04.tar.gz
application/octet-stream 17.1k

Message body not shown because it is not plain text.

Download (untitled) / with headers
text/plain 229b
Thank you for your detailed report and proposed solution. Please accept my apology for this tardy response. I believe version 1.05 should address your concerns - if not, please submit a new ticket. (I promise a faster response!)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.