In a previous article, "Bravo" said:
For you computer savvy folks in the newsgroup..... if I wanted to build a
web page for my airport that provided live METAR data, where could I get the
data from ? I see that the NWS web site has free software for decoding the
Do what I do for
http://xcski.com/~ptomblin/taf.html - write a perl script
to go out to the NOAA site and download it, and run it once an hour or two
out of cron.
#!/usr/bin/perl -w
# Get TAF file
use Net::FTP;
use Net::FTP::dataconn;
my @stations = ("KROC", "KBUF", "KSYR", "KART", "CYOW");
my $ftp = Net::FTP-new("weather.noaa.gov", Timeout = 600, Passive = 1);
if (!$ftp)
{
die "couldn't open ftp site";
}
$ftp-login("anonymous");
my $br = 'BR';
$ftp-cwd("/data/forecasts/taf/stations/");
my $outstr = "HTMLHEADTITLELocal Aviation Weather/TITLE/HEAD\n";
$outstr .= "BODYH1TAFs/H1\n";
$outstr .= "TABLE BORDER=1\n";
foreach $station (@stations)
{
$outstr .= "TR\n";
$outstr .= "TD$station/TD\n";
my $dataconn = $ftp-retr($station . ".TXT");
die "TAF can't get $station" if (!defined($dataconn));
my $taf;
my $numbytes = $dataconn-read($taf, 10000);
$taf =~ s/\n/$br\n/g;
$outstr .= "TD$taf/TD\n";
$outstr .= "/TR\n";
$dataconn-abort;
}
$outstr .= "/TABLE\n";
$outstr .= "H1METARs/H1\n";
$ftp-cwd("/data/observations/metar/stations/");
$outstr .= "TABLE BORDER=1\n";
foreach $station (@stations)
{
$outstr .= "TR\n";
$outstr .= "TD$station/TD\n";
my $dataconn = $ftp-retr($station . ".TXT");
die "METAR can't get $station" if (!defined($dataconn));
my $metar;
my $numbytes = $dataconn-read($metar, 10000);
$metar =~ s/\n/$br\n/g;
$dataconn-abort;
$outstr .= "TD$metar/TD\n";
$outstr .= "/TR\n";
}
$outstr .= "/TABLE\n";
$ftp-quit;
$outstr .= "/BODY/HTML\n";
my $fn = shift;
open(TAF, "$fn") ;
print TAF $outstr;
close TAF;
--
Paul Tomblin
http://xcski.com/blogs/pt/
"Legacy (adj): an uncomplimentary computer-industry epithet that
means 'it works'." -- Anthony DeBoer