O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


EMAIL HACK

wikipedia: Article of the Day
Grabs the "Article of the Day" from wikipedia.com and emails it to you. Similar to dictionary "Word of the Day" features.

Contributed by:
C M
[08/26/04 | Discuss (0) | Link to this hack]

#!/usr/bin/perl

use Mail::Sendmail;
#
#   Get the Article of the Day from Wikipedia and email it to someone
#
#   NEEDS:
#       In order for this script to work properly (without modification), you'll need a couple of things
#       *   Mail::Sendmail perl module
#       *   cron (if you want this to be sent to you daily without you thinking about it
#       *   wget
#
#       For windows users, all of this is  available under the Cygwin packages.
#


#
#   Change $to to reflect where you want the message to be sent
#
$to = 'firstEmail@foo.com, secondEmail@bar.com, etc..';
#
#   Change $from to reflect your email address
#
$from = 'youraddress@email.com';
$subject= "Featured Wikipedia Article of the day";
$wget = "/usr/bin/wget";
##
##
##   Shouldn't need to change anything below....
##
##
$data = `$wget -q -O - http://www.wikipedia.com`;
$data =~ s/\n/@@/g;
$data =~ s/img src=(@@)*"/img src="http:\/\/en.wikipedia.com/g;
$data =~ s/a href="/a href="http:\/\/en.wikipedia.com/g;
$match = "";
if ($data =~ /<h3>Today's featured article<\/h3>(.*?)Recently featured:/ ){
        $match = $1;
        $match =~ s/@@/\n/g; #print "$match\n";
        %mail = ( To => $to,  From => $from, Subject => $subject, Message => $match );
        $mail{'content-type'} = "text/html";
    sendmail(%mail) or die $Mail::Sendmail::error;
Source can be found here


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.