ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/www/trunk/bin/rss2html.pl
Revision: 245
Committed: Sat Sep 6 23:27:32 2008 UTC (15 years, 8 months ago) by laffer1
Content type: text/plain
File size: 2396 byte(s)
Log Message:
stop truncating the text

File Contents

# Content
1 #!/usr/bin/perl -w
2 # rss2html - converts an RSS file to HTML
3 # It take one argument, either a file on the local system,
4 # or an HTTP URL like http://slashdot.org/slashdot.rdf
5 # by Jonathan Eisenzopf. v1.0 19990901
6 # Copyright (c) 1999 Jupitermedia Corp. All Rights Reserved.
7 # See http://www.webreference.com/perl for more information
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13
14 # INCLUDES
15 use strict;
16 use XML::RSS;
17 use LWP::Simple;
18 use HTML::Strip;
19 use DateTime::Format::Mail;
20 use File::Temp qw(tempfile);
21 use File::Copy qw(move);
22
23
24 # MAIN
25 # check for command-line argument
26 die "Usage: rss2html.pl (<RSS file> | <URL>) <output file>\n" unless @ARGV == 2;
27
28 # get the command-line argument
29 my ($input, $output) = @ARGV;
30
31 # create new instance of XML::RSS
32 my $rss = XML::RSS->new;
33
34 # argument is a URL
35 if ($input=~ /http:/i) {
36 my $content = get($input) || die "Couldn't fetch $input\n";
37 # parse the RSS content
38 $rss->parse($content);
39
40 # argument is a file
41 } else {
42 die qq[File "$input" does't exist.\n] unless -e $input;
43 # parse the RSS file
44 $rss->parsefile($input);
45 }
46
47 # print the HTML channel
48 print_html($rss, $output);
49
50 # SUBROUTINES
51 sub print_html {
52 my ($rss, $output) = @_;
53
54 my ($fh, $filename) = tempfile() or die "Couldn't make tmpfile: $!\n";
55
56 print "FILENAME: $filename, output: $output\n";
57
58 print $fh qq[<div class="rssfeed">\n];
59
60 my $i =0;
61 my $desc;
62 my $title;
63 my $hs = HTML::Strip->new();
64
65 # print the channel items
66 foreach my $item (@{$rss->{'items'}}[0 .. 15]) {
67 next unless defined($item->{'title'}) && defined($item->{'link'});
68 $title = $item->{'title'};
69 $desc = $hs->parse($item->{'description'});
70
71 # Wed, 03 Sep 2008 06:58
72 my $date = DateTime::Format::Mail->parse_datetime($item->{pubDate})->strftime('%a, %d %b %Y %R');
73
74 print $fh "<blockquote class=\"bluebox\">\n";
75 print $fh qq[<h3>$date</h3>\n];
76 print $fh qq[<h4>$title</h4>\n];
77 print $fh qq{<p>$desc</p>\n};
78 print $fh "</blockquote>\n";
79 }
80
81 print $fh "</div>";
82
83 close($fh) || die "Couldn't close $filename: $!\n";
84
85 move($filename, $output);
86
87 }
88
89
90
91
92
93

Properties

Name Value
svn:executable *