#!/usr/bin/perl -w
# vim: set sw=4 ts=4 si et:
# read one or more of the rss files 
# and generate a list of links. 

use strict;

require XML::RSS;
#
#
my @news = ();
my ($item,$site,$rdfstring);
my ($desc,$title);

my $rss = new XML::RSS;

die "USAGE: lglinks_short lg22.rss .....\nThe generated html code is written to stdout\n" unless($ARGV[0]);
#push (@news, "<p><b><a href=\"http://www.linuxgazette.com\">Linux Gazette</a></b></p>\n");
#push (@news, "<small>\n");
for my $file (@ARGV){
    open(FF,$ARGV[0])||die "lglinks_short: ERROR can not read $file\n";
    $rdfstring="";
    while(<FF>){
        s/&/+.+/g; # this is to fix a bug in the XML::RSS
        $rdfstring.=$_;
    }
    close FF;
#
    if ($rdfstring && length($rdfstring)> 250) {
        $rss->parse($rdfstring);
        #$rss->parsefile($file);
        foreach $item (@{$rss->{'items'}}) {
            if ($item->{'description'}){
                    $desc=$item->{'description'};
                    #print STDERR $desc."\n";
            }else{
                    $desc="";
            }
            if ($item->{'title'}){
                    $title=$item->{'title'};
            }else{
                    $title="&lt;no title&gt;";
            }
            push (@news, "- <a href=\"$item->{'link'}\">$title</a><br>\n");
        }
    }else{
        die "ERROR: failed to get news from $ARGV[0]\n";
    }
}
#push (@news, "</small>\n");


if (scalar(@news) < 5){
    die "ERROR: less than 2 items \n";
}else{
    for (@news){
        s/\+\.\+/&amp;/g;
        print;
    }
}
1;