./weather.pl
__OUTPUT__
tnite: mostly clr eve, low clouds/ fog ovrngt. lows arnd
60. W wind arnd 15 mph eve.
Thu: low clouds/ fog am. othrwse mostly sunny. highs mid
60s to upr 70s. W wind 15 to 20 mph pm.
Thu nite: mostly clr eve, low clouds/ fog ovrngt. lows lwr
60s. W wind 15 to 20 mph eve.
Fri: low clouds/ fog am. othrwse mostly sunny. highs upr
60s/ 70s.
Fri nite: mostly clr eve, low clouds/ fog ovrngt. lows lwr
60s.
Sat - Wed: areas of nite/ am low clouds/ fog, othrwse
mostly clr. highs near 70 at beach to mid 70s to lwr 80s
inlnd. lows arnd 60.
####
./weather.pl 'Los Angeles' 'CA'
##
##
./weather.pl 'Los Angeles' 'CA' '1234567890@mobile.att.net'
##
##
perl weather.pl "Los Angeles" "CA" "1234567890@mobile.att.net" "mail.yourhost.com"
##
##
use strict;
use warnings;
use Geo::WeatherNOAA;
use MIME::Lite;
my ( $city, $state, $email, $mailhost ) = @ARGV;
$city = $city || 'Los Angeles';
$state = $state || 'CA';
if ( $^O =~ /MSWin32/ and defined $mailhost ) {
MIME::Lite->send( 'smtp', $mailhost, Timeout=>60 )
}
{
my %abbrev = map { chomp; split /\s*\|\s*/ } ;
my $keywords = join '|', keys %abbrev;
sub abbreviate {
my ( $prefix, $text ) = @_;
my $out = lc ( $prefix . ': ' . $text );
$out =~ s/\b($keywords)\b/$abbrev{$1}/g; # Abbreviate
$out =~ s/\.{3}/./; # Repunctuate
$out =~ s/\s\bin\b//g; # drop 'in'
$out =~ s/\s\bthe\b//g; # drop 'the'
$out =~ s/\s*([,.;\/]+)\s*/$1 /g; # Too much space.
return $out;
}
}
my ( $date, $warnings, $forecast, $coverage ) =
process_city_zone( $city , $state, '', 'get');
foreach my $warning ( @$warnings ) {
if ( $warning =~ /\w/ ) {
my $out = abbreviate ( '!!!', $warning );
if ( defined $email ) {
my $msg = MIME::Lite->new(
'From' => $email,
'To' => $email,
'Subject' => 'Warning',
'Data' => $out
);
$msg->send;
} else {
print "Warning:\n$out\n";
}
}
}
foreach my $frame ( @{ prepare_forecast( $forecast ) } ) {
if ( defined $email ) {
my $msg = MIME::Lite->new(
'From' => $email,
'To' => $email,
'Subject' => 'Forecast',
'Data' => $frame
);
$msg->send;
} else {
print "$frame\n";
}
}
sub prepare_forecast {
my ( $info ) = shift;
return [
map {
abbreviate( $_, $info->{$_} )
} keys %$info
];
}
__DATA__
tonight| tnite
patchy| ptch
clear| clr
evening| eve
cloudy| cldy
overnight| ovrngt
upper| upr
morning| am
afternoon| pm
south| S
north| N
east| E
west| W
northeast| NE
southeast| SE
southwest| SW
northwest| NW
winds| wind
monday| Mon
tuesday| Tue
wednesday| Wed
thursday| Thu
friday| Fri
saturday| Sat
sunday| Sun
tomorrow| Tomrw
through| -
otherwise| othrwse
then| ,
night| nite
inland| inlnd
beaches| beach
lower| lwr
and| /
around| arnd