#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
#-------------------------------------------------------------------------------
# Program: weather_mail
# Arguments: none
# Return value: undefined
#
#-------------------------------------------------------------------------------
require LWP::UserAgent;
use Mail::Mailer;
#
# OK, so the first thing is to go and get our forecast using HTTP::Request
#
# We get this from the British Meteorological Office on a specific page
# http://www.meto.gov.uk/datafiles/offshore.html
#
my $ua = LWP::UserAgent->new;
#
# OK, we need to grab this through a proxy since we're behind a firewall
#
$ua->proxy('http', 'http://web-proxy.nn.nn.com:8088/');
#
# So go and grab the page
#
my $request = HTTP::Request->new('GET', 'http://www.meto.gov.uk/datafiles/offshore.html');
my $response = $ua->request($request);
#
# If it worked
#
if ($response->is_success) {
$_ = $response->content;
/^AT ([0-9]+).* ([0-9]+) ([A-Z]{3}).* ([0-9]{4})
/mi;
my $date_of_forecast = "ISSUED: $1 $2/$3/$4";
$_ = $response->content;
/(.*PORTLAND.*
\n)((^.+
\n)+)
/mi;
my $forecast = sprintf("%s\n%s %s\n", $date_of_forecast, $1,$2);
my %swaps = (# From To
"OCCASIONALLY", "OCC.",
"MILES", "M.",
"SHOWER", "SHWR",
"RAIN", "RN",
"THUNDER", "THNDR",
" +", " ",
"ERLY", "",
"EXPECTED", "EXP",
"SLOW", "SLW",
"INCREASING", "INC",
"DECREASING", "DEC",
"NORTH", "N.",
"EAST", "E.",
"SOUTH", "S.",
"WEST", "W.",
"
", ""
);
foreach (keys(%swaps)) {
$forecast =~ s/$_/$swaps{$_}/gi;
}
my $mailer = Mail::Mailer->new;
$mailer->open({ From => "nn\@nn.co.uk",
To => "nn\@nn.co.uk",
Subject => "",
})
or die "Can't open: $!\n";
print $mailer $forecast;
$mailer->close();
}