Friday, October 22, 2004

Bill Bailey's blog

Bill Bailey has a blog! Bill Bailey's blog doesn't have a feed! Solution:

#!/usr/bin/perl -w

use strict;
use XML::RSS;
use LWP::Simple;
use HTML::Entities;

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

$page = get("http://www.bill-bailey.co.uk/blog/index.php");
$rss->channel(title       => 'Bill Bailey',
              link        => 'http://www.bill-bailey.co.uk/blog/index.php',
              description => 'Bill Bailey\'s Blog');
      
my @chunks = split ('<table border="0" cellspacing="0" cellpadding="0">', $page);

my ($date, $link, $content, $title);

foreach (@chunks)
{
	if (/<td class="BlogTitle">\s*([^\r\n]*)[\r\n\s]*<\/td>/is)
        {
		$date = $1;	
	}
	if (/<td class="BlogHeader">\s*([^\r\n]*)[\r\n\s]*<\/td>/is)
	{
		$title = $1;
	}
	if (/<td class="BlogText">(.*)<\/td>\s*<\/tr>\s*<tr>\s*<td>&nbsp;/is)
	{
		$content = encode_entities($1);
	}
	if (/<td class="BodyText">\s*<a href="([^"]*)">Read comments/is)
	{
		$link = "http://www.bill-bailey.co.uk$1";
	}
	if ($date && $title && $content && $link)
	{
		$rss->add_item(title       => $title,
			       link        => $link,
		       	       description => $content,
		       	       dc => {date => $date});

	}
}

print $rss->as_string;
More Bill Bailey here.

0 Comments:

Post a Comment

<< Home