Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RE: RE: Oblivious?

by Odud (Pilgrim)
on Jun 21, 2000 at 17:47 UTC ( [id://19240]=note: print w/replies, xml ) Need Help??


in reply to (jcwren) RE: Oblivious?
in thread Oblivious?

Another good thing is get a weather report from your local airport (METAR format, there is a module on CPAN to help with the decoding), this can save a lot of wasted time looking out of the window etc.

Replies are listed 'Best First'.
RE: RE: RE: Oblivious?
by ase (Monk) on Jun 23, 2000 at 00:18 UTC
    To that effect I submit the following:
    Requires: Geo::METAR
    #!/usr/bin/perl -w # Gets METAR information from my Favorite Airports and # displays temp and wind speed direction. use LWP::UserAgent; use Geo::METAR; use strict; my $ua = LWP::UserAgent->new; my $uri = "http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc="; my $m = new Geo::METAR; #airport codes my %code = ( Renton => 'krnt', Ephrata => 'keph', Boeing_Field => 'kbfi', CourDAlene => 'kcoe', Sea_Tac => 'ksea', ); my (%site,$key,$value); while (($key,$value) = each %code) { $site{$value}=$key; } for (keys %code) { $uri .= $code{$_} . "%20"; } my $req = HTTP::Request->new('GET',$uri); my $res = $ua->request($req); if ($res->is_success) { my @content = split("\n",$res->content); if (@content) { for (@content) { if (/\d{6}Z/) { $m->metar($_); print <<"EOT"; Site: $site{lc($m->{SITE})} Time: $m->{TIME} Temp: $m->{F_TEMP} deg F. Wind: $m->{WIND_MPH} mph. Dir: $m->{WIND_DIR_ENG} EOT } } } } else { print "Error: " . $res->status_line . "\n"; }

    Update: Per Odud's excellent suggestion, I added error checking on the get. This meant usingLWP::UserAgent rather than LWP::Simple

      The only suggestion I would make is to improve the error handling around the get. I had occasional timeouts when I tried it that didn't get reported back. Geo::METAR has problems with some of the UK data, for example, visibility is reported as a four digit number in meters rather than statute miles. But nothing that a quick hack around the code can't fix.
        Thanks for the Suggestion Odud, I updated the code to use LWP::UserAgent rather than LWP::Simple, so that the response code could be checked.

        As to the UK data problem, maybe a note to the Geo::METAR author is in order? (Or a patch)
        Cheers,
        -ase

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://19240]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-16 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found