/usr/share/doc/libgeo-metar-perl/examples/fetch_temp.pl is in libgeo-metar-perl 1.15-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/usr/bin/perl -w
# $Id: fetch_temp.pl,v 1.1 2007/11/13 21:19:27 koos Exp $
# Brief Description
# =================
#
# fetch_temp.pl is a program that demonstrates how to get the current
# temperature from a nearby (or not) airport using Geo::METAR and the
# LWP modules.
#
# Given an airport site code on the command line, fetch_temp.pl
# fetches the current temperature and displays it on the
# command-line. For fun, here are some example airports:
#
# LA : KLAX
# Dallas : KDFW
# Detroit: KDTW
# Chicago: KMDW
# Get the site code.
my $site_code = shift @ARGV;
die "Usage: $0 <site_code>\n" unless $site_code;
# Get the modules we need.
use Geo::METAR;
use LWP::UserAgent;
use strict;
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request GET =>
"http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=$site_code";
my $response = $ua->request($req);
if (!$response->is_success) {
print $response->error_as_HTML;
my $err_msg = $response->error_as_HTML;
warn "$err_msg\n\n";
die "$!";
} else {
# Yep, get the data and find the METAR.
my $m = new Geo::METAR;
my $data;
$data = $response->as_string; # grap response
$data =~ s/\n//go; # remove newlines
$data =~ m/($site_code\s\d+Z.*?)</go; # find the METAR string
my $metar = $1; # keep it
# Sanity check
if (length($metar)<10) {
die "METAR is too short! Something went wrong.";
}
# pass the data to the METAR module.
$m->metar($metar);
# ask for the temperature(s)
my $f_temp = $m->TEMP_F;
my $c_temp = $m->TEMP_C;
my $time = localtime(time);
print "The temperature at $site_code is $f_temp F ($c_temp C) as of $time.\n";
} # end else
exit;
__END__
|