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 with the correct MIME type:

$rss->channel(
    title       => "Today's Doonesbury",
    link        => "http://www.doonesbury.com",
    description => "Doonesbury, by Garry Trudeau"
);

print header('application/xml+rss'),
print $rss->as_string;

You can obviously use this sort of code to produce RSS feeds of any online comic strip. Do the author a favor, however: don’t make the feed public, visit his site once in a while, and buy some schwag. You’re getting great stuff for free—with the added convenience you’ve added, for sure—and it’s nice to give something back.

The Entire Listing

#!/usr/bin/perl

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

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

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

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

$rss->channel(
    title       => "Today's Doonesbury",
    link        => "http://www.doonesbury.com",
    description => "Doonesbury, by Garry Trudeau"
);

print header('application/xml+rss'),
print $rss->as_string;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.35.75