[bglug] Weather Report

k|b|s kbs@bglug.it
Mar 21 Ott 2008 10:08:31 CEST


Non si tratta di Jaco Pastorius, ma del solito inutile script.
Volete le condizioni/previsioni del tempo sul desktop? Ci sono una marea
di applet e pythonate varie all'uopo, ma nessuna vi soddisfa.
L'unica è affidarsi ai rapporti metar degli aeroporti, pertanto aprite
una shell cpan e >> install Geo::METAR
Poi passate lo script a conky, torsmo o root-tail.
Have fun ;^)

#!/usr/bin/perl -w
# Wheater_Report By Joe Galaxy
#
# Configura il codice metar qui sotto, ad es.
# Udine / Campoformido (16044, LIPD)
# Udine / Rivolto (16045, LIPI)
# Trieste (16110, LIVT)
# Bergamo / Orio Al Serio (16076, LIME) 

# Oppure passalo direttamente alla cli
# ./weater_report <$site_code>

# Configure:
my $site_code = shift @ARGV || "LIME";

use Data::Dumper;
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);

my $m = new Geo::METAR;
$m->debug(0);
my $data;
$data = $response->as_string;
$data =~ s/\n//go;
$data =~ m/($site_code\s\d+Z.*?)</go;
my $metar = $1;

# Sanity check

if ( length($metar) < 10 ) {
    die "Errore! Evacuate l'edificio!";
}

# passa i dati
$m->metar($metar);

# variabili
my $r_type          = $m->TYPE;
my $c_temp          = $m->TEMP_C;
my $site            = $m->SITE;
my $m_time          = $m->TIME;
my $wind_dir_eng    = $m->WIND_DIR_ENG;
my $wind_kts        = $m->WIND_KTS;
my $wind_visibility = $m->VISIBILITY;
my $alt             = $m->ALT;
my @cur_weather     = @{ $m->WEATHER() };
my @cur_sky         = @{ $m->SKY() };
my $dew_point       = $m->DEW_C;

# e scrive
print "$r_type for $site\n";
print "    Conditions at $m_time\n\n";
print "Temp:\t\t $c_temp C\n";
print "Dew point:\t $dew_point C\n";
printf qq{Humidity:\t %.2f %%\n},100*($dew_point)/($c_temp);
print "Wind:\t\t $wind_kts Kts\n";
print "Wind Dir:\t $wind_dir_eng\n";
print "Visibility:\t $wind_visibility\n";
print "Sky:\t\t @cur_sky\n";
printf qq{Pressure:\t %.4f hPa\n},33.863890218824522825644371143134*($alt);
print "Weather:\t @cur_weather\n";

exit;

__END__



-- 
mailto: ʇı̣˙ɓnƮɓq@sqʞ


Maggiori informazioni sulla lista bglug