#!/home/mschilli/PERL/bin/perl -w use strict; use LWP::Simple; use Cache::FileCache; use HTML::TreeBuilder; use Log::Log4perl qw(:easy); use Mail::Mailer; use Pod::Usage; Log::Log4perl->easy_init($DEBUG); my($forum_id, $email) = @ARGV; $forum_id && $forum_id =~ /^\d+$/ or pod2usage("No valid forum ID"); $email && $email =~ /\@/ or pod2usage("No valid forum ID"); my $cache = Cache::FileCache->new({ cache_root => "$ENV{HOME}/data", namespace => "sf-forum", }); my $URL = "http://sourceforge.net/forum/forum.php?forum_id=$forum_id"; (my $html = get $URL) or LOGDIE "Cannot get $URL ($!)"; my $tree = HTML::TreeBuilder->new(); $tree->parse($html) or LOGDIE "Cannot parse HTML"; my $email_text; for(@{$tree->extract_links()}) { # Hyperlinks extrahieren my ($linkname, $reference) = @$_; next unless $linkname =~ /thread_id/; my $text = $reference->as_text(); $text =~ s/^\s*//; $text =~ s/\s*$//; unless($cache->get($text)) { $email_text .= "$text\n"; } $cache->set($text, 1); } if(defined $email_text) { mail_message($email, "New message on Sourceforge forum $forum_id", "New on $URL:\n" . $email_text, $email); } ############################################################ sub mail_message { ############################################################ my($from, $subject, $text, @to) = @_; my $mailer = Mail::Mailer->new('sendmail'); my $to = shift @to; my @ccline = @to > 0 ? ('Cc', join(', ', @to)) : (); $mailer->open( { From => $from, To => $to, @ccline, Subject => $subject, }); print $mailer $text; $mailer->close; } __END__ =head1 NAME sf-forum-watch - Watch a Sourceforge forum and send notifications =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS sf-forum-watch forum_id email@somewhere.com =head1 DESCRIPTION This script gets called periodically and checks if there's new discussions on a Sourceforge forum. =head1 EXAMPLES # Watch the Log4perl forum $ sf-forum-watch 190825 email@somewhere.com =head1 LEGALESE Copyright 2006 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2006, Mike Schilli