#!/usr/bin/perl -w # # Usage: airnav.pl [airport] # # where airport is the 3 letter airport code (US airports only) # # A quick script to download a page from airnav, parse it # and extract the METAR and TAF data from it. Useful for # getting a quick (and unofficial) look at the weather at # an airport. # # # # Copyright 2004 Frank Adelstein. All Rights Reserved. # # Permission to use, copy, modify, and distribute this # software is hereby granted without fee, provided that # the copyright notice and permission notice are not removed. # # --FNA 2004/20/08 # my $METAR=0; my $TAF=0; my $wget = "wget -o /dev/null -O -"; my $URL = "http://www.airnav.com/airport/"; my $airport = shift; my $out; my $str = ""; my $Tstr = 'TAF'; if (defined ($airport)) { $airport = uc $airport; } else { $airport = "KITH"; } $URL .= $airport; open (PIPE, "$wget $URL | ") || die "can't open pipe to wget"; #open (PIPE, "$airport") || die "can't open pipe to wget"; while () { if ($METAR && /$str.*$airport(.*)/i) { $out = $1; $out = $1; $out =~ s/<[^>]*>/ /g; print "$airport METAR: $out\n"; $METAR = 0; } if ($TAF && /$str.*$airport(.*)/i) { $out = $1; $out =~ s/<[^>]*>/ /g; print "$airport TAF: $out\n"; $METAR = 0; } if (/METAR/) { $METAR = 1; } if (/$Tstr/) { $TAF = 1; } } close PIPE;