Skip to Main Content
Developing Feeds with RSS and Atom
book

Developing Feeds with RSS and Atom

by Ben Hammersley
April 2005
Intermediate to advanced content levelIntermediate to advanced
270 pages
7h 13m
English
O'Reilly Media, Inc.
Content preview from Developing Feeds with RSS and Atom

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

How to Build an RSS 2.0 Feed

How to Build an RSS 2.0 Feed

Mark Woodman
Secrets of RSS

Secrets of RSS

Steven Holzner

Publisher Resources

ISBN: 0596008813Supplemental ContentErrata Page