#! /usr/bin/perl -w # PERL script to remind friends to write blogs, when they haven't # done so in N days (N=15 in this example). # # Questions and/or comments should be sent to mail@sgowtham.net # # First written : Gowtham, Fri, 02 Jun 2006 09:20:48 -0400 # Last modified : Gowtham, Fri, 13 Oct 2006 15:56:16 -0400 # # Pre-Requisites: # 0. Friends who write blogs # 1. Planet (or something like it) to aggregate your friends' blogs # into one place. # 2. Ability to use 'mail' or 'pine' from the commandline to send # emails, without having to enter password. This needs a working # mail server and contact your sys-admin if you need more details. # # Part 1 : Fetch the contents of aggregated blog page. # I use Planet for this purpose and it aggregates the blogs from last 15 days. # Fetched contents are stored in a file called 'index.txt' under the # current working directory. Change the URL to meet your requirements. use LWP::UserAgent; use URI::URL; $hdr = new HTTP::Headers(Accept => 'text/plain', UserAgent => 'GBrowser/1.0'); $url = new URI::URL('http://sgowtham.net/news/people/index.html'); $req = new HTTP::Request(GET, $url, $hdr); $uag = new LWP::UserAgent; $rpl = $uag->request($req); if ($rpl->is_success) { open (INDEX, "> ./index.txt"); print INDEX $rpl->content; close (INDEX); } else { print $rpl->message;} # # Part 2 : Create Hash-of-Hashes # This will contain list of bloggers, blog titles and email addresses. # Extend this to include as many friends you have. my %BLOGGERS = ( 'Friend0' => {'title' => 'Blog Title 0', 'email' => 'friend0\@someplace.com'}, 'Friend1' => {'title' => 'Blog Title 1', 'email' => 'friend1\@someplace.com'}, 'Friend2' => {'title' => 'Blog Title 2', 'email' => 'friend2\@someplace.com'}, 'Friend3' => {'title' => 'Blog Title 3', 'email' => 'friend3\@someplace.com'}, ); # # Part 3 : Send Reminders # Search the file 'index.txt' for bloggers' entry in the last 15 days # and remind them if there is none. This example uses 'mail' command. If # it's not available for you for any reason, consider using PINE (it can # be set up to send emails from commandline without entering password). $date = localtime; $file = "./index.txt"; foreach $key (keys %BLOGGERS) { $entry = qx(grep "$key" $file | wc -l); if ( $entry < 1 ) { print "Reminding $key \n"; open MAILBODY, "| mail -s 'Eager To Read Your Blog' $BLOGGERS{$key}->{'email'}" or die "Cannot send email,\n"; print MAILBODY "\n $date EST\n\n"; print MAILBODY " Dear $key\n\n"; print MAILBODY " It has been a while since you updated your blog,\n"; print MAILBODY " titled \"$BLOGGERS{$key}->{'title'}\",\n"; print MAILBODY " (none in the last 15 days or so). As you might\n"; print MAILBODY " (or might not) know, there are people eager to\n"; print MAILBODY " know about what's happening in your life and/or\n"; print MAILBODY " your thoughts about what's happening around you.\n"; print MAILBODY " If work's keeping you busy, it's OK - sacrifice a\n"; print MAILBODY " meal (or two) and update your blog... just kidding.\n"; print MAILBODY " Hopeful that it wouldn't be long to read one..."; print MAILBODY " \n\n"; print MAILBODY " Yours,\n"; print MAILBODY " YOUR NAME\n\n"; close (MAILBODY); } }