Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

cwest (1514)

  (email not shown publicly)
AOL IM: caseyrwest (Add Buddy, Send Message)

Perl geek.

Journal of cwest (1514)

Saturday July 13, 2002
06:12 PM

News Easy

[ #6331 ]


    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 ;


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

        <title>News Feeds</title>
        <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="[% %]"><img src="[% feed.image.url %]"
                          border="0" height="[% feed.image.height %]"
                          width="[% feed.image.width %]"
                          alt="[% feed.image.description %]"/></a>
                    [% ELSE %]
                        <b><a href="[% %]">[% %]</a></b>
                        [% %]<br />
                    [% END %]
                    [% IF %]
                        <form action="[% %]" method="GET">
                            <input type="text" name="[% %]" />
                            <input type="submit" value="[% feed.textinput.description %]" />
                    [% END %]
                        [% FOREACH item = feed.items %]
                            <b>-</b> <font size="-1">
                            <a href="[% %]">[% item.title %]</a></font><br />
                        [% END %]

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

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


My news is here, have fun on yours!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.