#!/usr/local/bin/perl
# Convert rss to html - rss2html.pl
#
# Usage : rss2html.pl > htmlfile.html
#
# Author : Kyo Nagashima
# E-Mail : kyo@hail2u.net
# URL : http://hail2u.net/
#
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
use strict;
die "Usage: rss2html.pl > htmlfile.html\n" unless @ARGV == 1;
use Jcode;
use XML::RSS;
use LWP::Simple;
my $rss = new XML::RSS;
my $j = new Jcode;
my $content;
my $html;
my $arg = shift;
if ($arg =~ /http:/i) {
$content = get($arg);
die "Error: Cannot find $arg\n" unless $content;
eval {
$rss->parse($content);
};
die "Error: Cannot parse $arg\n$@\n" if $@;
}
else {
$content = $arg;
die "Error: Cannot find $arg\n" unless -e $content;
eval {
$rss->parsefile($content);
};
die "Error: Cannot parse $arg\n$@\n" if $@;
}
&header;
my $chname = &trimenc($j->set(\$rss->{'channel'}->{'title'})->utf8);
my $chlink = &trimenc($j->set(\$rss->{'channel'}->{'link'})->utf8);
my $chdesc = &trimenc($j->set(\$rss->{'channel'}->{'description'})->utf8);
$html .= qq|\n|;
$html .= qq|- $chname
\n|;
$html .= qq|- \n|;
$html .= qq|
$chdesc
\n|;
$html .= qq|\n|;
for my $item (@{$rss->{'items'}}) {
my $itemname = &trimenc($j->set(\$item->{'title'})->utf8);
my $itemlink = &trimenc($j->set(\$item->{'link'})->utf8);
my $itemdesc = &trimenc($j->set(\$item->{'description'})->utf8);
$html .= qq|- $itemname
\n|;
$html .= qq|- $itemdesc
\n|;
}
$html .= qq|\t\t
\n|;
$html .= qq|\t \n|;
$html .= qq|
\n|;
&footer;
print STDOUT $j->set(\$html)->sjis;
exit;
# ---------------------------------------------------------------------------- #
sub header{
$html .= qq|\n|;
$html .= qq|\n|;
$html .= qq|\n|;
$html .= qq|\n|;
$html .= qq|rss2html\n|;
$html .= qq|\n|;
$html .= qq|\n|;
}
sub footer{
$html .= qq|\n|;
$html .= qq|\n|;
}
sub trimenc{
my $value = $_[0];
if ($value) {
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$value =~ s/&/&/g;
$value =~ s/&/&/g;
}
return $value;
}