Daily Doonesbury

The morning isn’t quite the same without the daily dose of Doonesbury, the Pulitzer Prize winning cartoon strip by Garry Trudeau. But, frankly, the nearest newspaper stand is far too far to go before I’ve had morning coffee and typing in http://www.doonesbury.com on an empty stomach is a bit much. Why not have it delivered via RSS? You just need a web server, or a proper operating system capable of running CGI scripts, and the following code. This is tremendously simple stuff—but distinctly pleasing to have set up for your morning coffee.

Walking Through the Code

We’ll go with the traditional start: strict;, warnings;, CGI with DATE::Manip, and the joy that is XML::RSS all being loaded for your coding pleasure. So far, so simple.

use strict;
use warnings;
use CGI qw(:standard);
use Date::Manip;
use XML::RSS;

The Doonesbury site, thankfully, names its image files after the date, in the format YYMMDD. So, first, you work out the date, then add a single entry containing escaped HTML that displays the image file you want.

my $todays_date = &UnixDate( "today", "%y%m%d" );
my $this_year = &UnixDate("today","%Y");

my $rss = new XML::RSS( version => '2.0' );

$rss->add_item(
    title => "Doonesbury for $todays_date",
    link  => "http://images.ucomics.com/comics/db/$this_year/db$todays_date.gif",
    description => '<img src="http://images.ucomics.com/comics/db/2004/'
      . "db$todays_date.gif"
      . '"/>'
);

Then it’s just a matter of adding in the channel information and serving the thing out ...

Get Developing Feeds with RSS and Atom now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.