perl:wetterdienst
#!/usr/bin/perl  -w
 
use strict;
use HTML::ExtractContent;
use LWP::UserAgent;
use Net::SMTP;
use DateTime;
use Encode;
 
# Declarations
my $MailServer = '???';
my $MailDomain = '???';
my $MailAccount = '???';
my $MailPassword = '???';
my $MailSender = 'foo@bar.com';
my $MailCharset = 'iso-8859-1';
my @MailRecipientTo = ('<foo@bar.net>');
my @MailRecipientCc = ('<foo@bar.de>', '<foo@bar.at>');
 
my @Sources = (
    {url => 'http://www.alpenverein.at/portal/Wetter/Zamg/wetter.htm',
    separator => '============= WETTER IN INNSBRUCK VON ALPENVEREIN.AT =============',
    regex => 0,
    ContentCode => 'AT-W'},
    {url => 'http://www.meteocentrale.ch/?country=ch&day=0&time=6&id=swiss&L=1',
    separator => '=============== WETTERBERICHT VON METEOCENTRALE.CH ===============',
    regex => 1,
    ContentCode => 'CH-W'},
    {url => 'http://www.meteocentrale.ch/de/uwz/unwetterzentrale/lagebericht.html',
    separator => '============== WARNLAGEBERICHT VON METEOCENTRALE.CH ==============',
    regex => 1,
    ContentCode => 'CH-U'}
);
 
# Getting current date and time in iso8601 format
my $dt = DateTime->now(time_zone => 'Europe/Berlin');
$dt->iso8601();
 
# Getting contant from Web pages
foreach (@Sources) {
  my @MailBody = ();
    my $agent = LWP::UserAgent->new;
    my $contentA = $agent->get($$_{'url'});
    my $contentB = $contentA->decoded_content;
    if ($$_{'regex'} eq 1)    {
        $contentB =~ s/\n/<br \/>/ig;
        $contentB =~ s/.*<dl class="textelement">//ig;
        $contentB =~ s/<\/dl>.*//ig;
        $contentB =~ s/<br \/>/\n/ig;
    }
 
    my $extractor = HTML::ExtractContent->new;
    $extractor->extract($contentB);
    my $result = $extractor->as_text;
 
    push(@MailBody, $$_{'separator'});
    push(@MailBody, ("", split(/\n/, encode($MailCharset, $result)), ""));
    push(@MailBody, "======================= ENDE DES BERICHTES =======================");
 
    # Sending Mail
    my $smtp = Net::SMTP->new(
        Host => $MailServer,
        Hello => $MailDomain,
        Timeout => 30,
        Debug => 0);
    die "Couldn't connect to server" unless $smtp;
    # print "Server connection opened\n";
 
    if ( !$smtp->auth($MailAccount, $MailPassword) ) {
    print "authentication failed or not needed\n";
    }
 
    $smtp->mail($MailSender);
    $smtp->to(@MailRecipientTo);
    $smtp->cc(@MailRecipientCc);
 
    $smtp->data();
    $smtp->datasend("From: Dein Wetterdienst<$MailSender>\n");
    $smtp->datasend("To: @MailRecipientTo\n");
    $smtp->datasend("Cc: @MailRecipientCc\n");
    $smtp->datasend("Subject: Wetterbericht ($$_{'ContentCode'}) - $dt\n");
    $smtp->datasend("MIME-Version: 1.0\n");
    $smtp->datasend("Content-type: text/plain; charset=$MailCharset\n");
    $smtp->datasend("\n");
    foreach (@MailBody) {
        $smtp->datasend("$_\n");
    }
    $smtp->dataend();
 
    $smtp->quit;
 
    undef(@MailBody);
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License