Categories
computers suck o canada

An RSS generator for CBC Channels

This isn’t perfect (seems to fail on some feeds), but mostly works for me:


#!/usr/bin/perl -w
# cdf2rss - converts CBC KlipFarm CDF to crude RSS
# created by scruss on 02004/11/12
# RCS/CVS: $Id: cdf2rss,v 1.3 2004/11/13 03:59:21 scruss Exp $
# takes one argument, a stream name. Currently known streams are:
#
# Arts Business Calgary Canada
# Edmonton Montreal Ottawa
# Science Sports Toronto
# Vancouver Winnipeg World
#
# returns a crude RSS 1.0 stream fashioned from the CBC CDF output.
use strict;
use integer;
use XML::Simple;
use XML::RSS;
use LWP::Simple;
use constant CDFURL => 'http://www.cbc.ca/cdf/servlet/getCDF';
my $cdf = get( join( '?lineup=', CDFURL, $ENV{'QUERY_STRING'} ) );
my $xs = new XML::Simple;
my $ref = $xs->XMLin($cdf);
my $rss = new XML::RSS( version => '1.0' );
$rss->channel(
title => join( ' ', 'CBC', $ref->{category} ),
description => join( ' ', 'CBC', $ref->{category} ),
link => $ref->{href}
);
foreach my $cdf_item ( @{ $ref->{item} } ) {
my $tmp_abstract = $cdf_item->{abstract};
$tmp_abstract =~ s/\s+/ /g;
$tmp_abstract =~ s/^ //;
$tmp_abstract =~ s/ $//;
$rss->add_item(
title => $cdf_item->{title},
link => $cdf_item->{href},
description => $tmp_abstract
);
}
print "Content-type: application/xml+rss\n\n", $rss->as_string;
exit;

3 replies on “An RSS generator for CBC Channels”

thanks for this…but any tips on putting the code to good use? i’ve messed around with it a bit (i don’t really know squat about perl), but the most practical thing i’ve been able to do is run the code on my c: drive (altered the code to write an .xml file) & generate live bookmarks in firefox (but only for the Arts feed, which appears to be the default — i’m still trying to figure out how to pass an argument to perl from the command line). oh, and one bug: the <description> contents are missing all their s’s…

As it stands, it’s designed to run from a server. You access the feeds
by calling something like:

http://yourdomain.ca/cgi-bin/cdf2rss?Edmonton

or

http://yourdomain.ca/cgi-bin/cdf2rss?World

for the Edmonton or World Feeds.

If you want to generate a file, change the line that reads:

my $cdf = get( join( ‘?lineup=’, CDFURL, $ENV{’QUERY_STRING’} ) );

to

my $cdf = get( join( ‘?lineup=’, CDFURL, $ARGV[0] ) );

and the line:

print “Content-type: application/xml+rss\n\n”, $rss->as_string;

to

print $rss->as_string;

Then you could run it like:

cdf2rss Toronto > cbc_toronto.xml

The missing sibilant problem was down to WordPress eating ‘\’ characters. It’s fixed on the page now, thanks.

Thanks, but you’re going to have to spell it out for a me a bit, if you don’t mind. I’ve saved this as .pl and .cgi and I still get a 500 and a 404 every time I try to call the file as you suggested.

What do I have to save it as?

Leave a Reply

Your email address will not be published. Required fields are marked *