#!/usr/bin/perl -w use strict; $|++; use XML::RSS; use LWP::Simple qw(mirror is_success); ## BEGIN config my $MAIL_TO = 'merlyn@XXstonehenge.comXX'; my $MAIL_FROM = 'merlyn@XXstonehenge.comXX'; my $MAIL_SUBJECT = "All the news that fits, we print!"; my $MAILHOST = "localhost"; my $DIR = "/home/merlyn/.rssnews"; my @NEWS = ( ## Perl News "http://www.news.perl.org/perl-news-short.rdf" => "perl-news-short.rdf", ## Slashdot "http://slashdot.org/slashdot.rdf" => "slashdot.rdf", ## CNET computing news "http://alchemy.openjava.org/rss/news-com.rdf" => "cnet-computing-news.rdf", ## Freshmeat "http://freshmeat.net/backend/fm.rdf" => "freshmeat.rdf", ## Linux Today "http://linuxtoday.com/backend/my-netscape.rdf" => "linuxtoday.rdf", ## Linux Planet "http://www.linuxplanet.com/rss" => "linuxplanet.rdf", ## Mac Central "http://www.maccentral.com/mnn.cgi" => "maccentral.rdf", ## Macweek.com "http://macweek.zdnet.com/macweek.xml" => "macweek.rdf", ## Moreover Computer Security "http://www.moreover.com/cgi-local/page?index_computersecurity+rss" => "moreover-computer-security.rdf", ); ## END config chdir $DIR or die "Cannot chdir $DIR: $!"; my @output; while (@NEWS >= 2) { my ($url, $localname) = splice @NEWS, 0, 2; dbmopen my %SAW, $localname, 0644 or warn "Cannot open %SAW for $localname: $!"; next unless is_success(mirror($url, $localname)); my $rss = XML::RSS->new or die "can't create XML::RSS?"; eval {$rss->parsefile($localname)} and not $@ or (warn "cannot parse $localname: $@"), next; my %seen; my @item_output; for my $item (@{$rss->{items}}) { my ($title, $link, $description) = @$item{qw(title link description)}; $description = "" unless defined $description; my $tag = "$title\0$link"; $seen{$tag} = time; next if $SAW{$tag}; push @item_output, "$tag\0$description"; } %SAW = %seen; if (@item_output) { push @output, "== ".($rss->channel("title"))." ==\n", map { my ($title, $link, $description) = split /\0/; "$title\n", " \n", (length $description ? " $description\n" : ()); } @item_output; } } if (@output) { require Net::SMTP; my $m = Net::SMTP->new($MAILHOST) or die "Cannot connect to mail $MAILHOST: $!"; $m->mail($MAIL_FROM) or die "Cannot set mail from: $!"; $m->to($MAIL_TO) or die "Cannot set mail to: $!"; $m->data("From: $MAIL_FROM\n", "To: $MAIL_TO\n", "Subject: $MAIL_SUBJECT\n", "\n", @output, ) or die "Cannot send contents: $!"; $m->quit or die "Cannot close mail: $!"; }