News Easy

cwest on 2002-07-13T23:12:09

Update
I've changed several things. New URL RSS For Guardian UK Script to get RSS feeds TT Template


I decided that I hate surfing all over for the days news, the news I want to read. I wrote some code to make life simple for me. Here it is, enjoy.

A cron job to download news:

#!/usr/bin/perl -w use strict; $| = 1;

use LWP::Simple;

chdir "/home/cwest/geeknest/html/news"; unlink <*>;

my $file = 'aaaa';

head $_ && chomp and mirror $_ => $file++ while ;

__DATA__ http://use.perl.org/journal.pl?op=top&content_type=rss http://use.perl.org/useperl.rss http://slashdot.org/slashdot.rss


The next thing is a Template Toolkit template to read and display the news. This is kind of modular already and could fit into any Template Toolkit setup you already have. I use Apache::Template to parse HTML files, so that's how I did it.

The format sucks on this page, but I tried hard enough to make it pretty, I'm done trying now. :-)

<html> <head> <title>News Feeds</title> </head> <body> <h2>News of the Day</h2> <hr /> [% USE newsdir = Directory( "/var/www/html/news" );

MACRO news_box( news_file ) BLOCK; USE feed = XML.RSS( news_file ); %] <table border="0" cellpadding="2" cellspacing="0"><tr><td> [% IF feed.image.url %] <a href="[% feed.image.link %]"><img src="[% feed.image.url %]" border="0" height="[% feed.image.height %]" width="[% feed.image.width %]" alt="[% feed.image.description %]"/></a> [% ELSE %] <b><a href="[% feed.channel.link %]">[% feed.channel.title %]</a></b> [% feed.channel.description %]<br /> [% END %] [% IF feed.textinput.link %] <form action="[% feed.textinput.link %]" method="GET"> <input type="text" name="[% feed.textinput.name %]" /> <input type="submit" value="[% feed.textinput.description %]" /> </form> [% END %] <p> [% FOREACH item = feed.items %] <b>-</b> <font size="-1"> <a href="[% item.link %]">[% item.title %]</a></font><br /> [% END %] </p> </td></tr></table> [% END;

USE table( newsdir.files, rows => 3 );

'<table border="1" cellpadding="0" cellspacing="0">'; FOREACH row = table.cols; "<tr>"; FOREACH item = row; '<td valign="top">'; IF item; news_box( item.path ); END; "</td>"; END; "</tr>"; END; "</table>"

%] </body> </html>


My news is here, have fun on yours!