[SimBot-commits] CVS: simbot/tools create_wx_station_db.pl,1.1,1.2
Status: Abandoned
Brought to you by:
kstange
|
From: Kevin S. <ks...@us...> - 2005-05-07 03:43:31
|
Update of /cvsroot/simbot/simbot/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25291/tools Modified Files: create_wx_station_db.pl Log Message: This works for me. It makes it so that since my LWP doesn't support gzip, it doesn't explode. Index: create_wx_station_db.pl =================================================================== RCS file: /cvsroot/simbot/simbot/tools/create_wx_station_db.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- create_wx_station_db.pl 7 May 2005 02:35:59 -0000 1.1 +++ create_wx_station_db.pl 7 May 2005 03:43:18 -0000 1.2 @@ -62,8 +62,11 @@ EOT # Set up our user agent my $ua = LWP::UserAgent->new; -$ua->default_header('Accept-Encoding' => 'gzip, deflate'); - +if (defined &HTTP::Response::decoded_content) { + $ua->default_header('Accept-Encoding' => 'gzip, deflate'); +} else { + print "Warning: Your HTTP::Response does not support gzip\n"; +} # Now with the boring stuff down, get the rather large METAR list print "Downloading METAR station list... "; @@ -74,7 +77,12 @@ if($response->is_error) { . $response->message . "\n"; } else { print "Done!\nReading it in"; - my $content = $response->decoded_content; + my $content; + if (defined &HTTP::Response::decoded_content) { + $content = $response->decoded_content; + } else { + $content = $response->content; + } my $cur_line; my $line_count = 0; @@ -87,15 +95,17 @@ if($response->is_error) { ($cur_line, $content) = split(/\n/, $content, 2); my ($station, undef, undef, $name, $state, $country, undef, $lat_dms, $long_dms) = split(/;/, $cur_line, 10); - my ($long_deg); - my ($lat_deg, $minutes, $seconds, $dir) = $lat_dms - =~ m/(\d+)-(\d+)(?:-(\d+))?([NS])/; - $lat_deg = &dms_to_degrees($lat_deg, $minutes, $seconds, $dir); - - ($long_deg, $minutes, $seconds, $dir) = $long_dms - =~ m/(\d+)-(\d+)(?:-(\d+))?([EW])/; - $long_deg = &dms_to_degrees($long_deg, $minutes, $seconds, $dir); - + my ($lat_deg, $long_deg, $minutes, $seconds, $dir); + if (defined $lat_dms) { + ($lat_deg, $minutes, $seconds, $dir) = $lat_dms + =~ m/(\d+)-(\d+)(?:-(\d+))?([NS])/; + $lat_deg = &dms_to_degrees($lat_deg, $minutes, $seconds, $dir); + } + if (defined $long_dms) { + ($long_deg, $minutes, $seconds, $dir) = $long_dms + =~ m/(\d+)-(\d+)(?:-(\d+))?([EW])/; + $long_deg = &dms_to_degrees($long_deg, $minutes, $seconds, $dir); + } { no warnings qw( uninitialized ); $update_station_query->execute( @@ -123,7 +133,13 @@ if($response->is_error) { } else { print "Done!\nReading it in"; my $xml; - if (!eval { $xml = XMLin($response->decoded_content, SuppressEmpty => 1); }) { + my $content; + if (defined &HTTP::Response::decoded_content) { + $content = $response->decoded_content; + } else { + $content = $response->content; + } + if (!eval { $xml = XMLin($content, SuppressEmpty => 1); }) { print STDERR " Failed!\n$@\n"; } else { my $update_station_query = $dbh->prepare( |