5 # this has been taken from Geo::METAR
10 # fetch_staf.pl is a program that demonstrates how to get the current
11 # short TAF for an airport.
13 # Given an airport site code on the command line, fetch_staf.pl
14 # fetches the short TAF and displays it on the
15 # command-line. For fun, here are some example airports:
22 # and of course: EGSH (Norwich)
27 my $site_code = uc shift @ARGV;
29 die "Usage: $0 <site_code>\n" unless $site_code;
31 # Get the modules we need.
37 my $ua = new LWP::UserAgent;
39 my $req = new HTTP::Request GET =>
40 "http://weather.noaa.gov/cgi-bin/mgetstaf.pl?cccc=$site_code";
42 my $response = $ua->request($req);
44 if (!$response->is_success) {
46 print $response->error_as_HTML;
47 my $err_msg = $response->error_as_HTML;
53 # Yep, get the data and find the TAF.
57 $data = $response->as_string; # grap response
58 $data =~ s/\n//go; # remove newlines
59 $data =~ m/($site_code\s\d+Z.*?)</go; # find the TAF string
60 my $taf = $1; # keep it
64 if (length($taf)<10) {
65 die "TAF is too short! Something went wrong.";
68 # pass the data to the TAF module.
71 print $m->as_string, "\n";