[Midnightbsd-cvs] www: www/bin: add rss scripts so we have them
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Sep 6 19:24:41 EDT 2008
Log Message:
-----------
add rss scripts so we have them
Added Files:
-----------
www/bin:
rss.sh (r1.1)
rss2html.pl (r1.1)
rss2htmlsum.pl (r1.1)
-------------- next part --------------
--- /dev/null
+++ bin/rss2html.pl
@@ -0,0 +1,93 @@
+#!/usr/bin/perl -w
+# rss2html - converts an RSS file to HTML
+# It take one argument, either a file on the local system,
+# or an HTTP URL like http://slashdot.org/slashdot.rdf
+# by Jonathan Eisenzopf. v1.0 19990901
+# Copyright (c) 1999 Jupitermedia Corp. All Rights Reserved.
+# See http://www.webreference.com/perl for more information
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# INCLUDES
+use strict;
+use XML::RSS;
+use LWP::Simple;
+use HTML::Strip;
+use DateTime::Format::Mail;
+use File::Temp qw(tempfile);
+use File::Copy qw(move);
+
+
+# MAIN
+# check for command-line argument
+die "Usage: rss2html.pl (<RSS file> | <URL>) <output file>\n" unless @ARGV == 2;
+
+# get the command-line argument
+my ($input, $output) = @ARGV;
+
+# create new instance of XML::RSS
+my $rss = XML::RSS->new;
+
+# argument is a URL
+if ($input=~ /http:/i) {
+ my $content = get($input) || die "Couldn't fetch $input\n";
+ # parse the RSS content
+ $rss->parse($content);
+
+# argument is a file
+} else {
+ die qq[File "$input" does't exist.\n] unless -e $input;
+ # parse the RSS file
+ $rss->parsefile($input);
+}
+
+# print the HTML channel
+print_html($rss, $output);
+
+# SUBROUTINES
+sub print_html {
+ my ($rss, $output) = @_;
+
+ my ($fh, $filename) = tempfile() or die "Couldn't make tmpfile: $!\n";
+
+ print "FILENAME: $filename, output: $output\n";
+
+ print $fh qq[<div class="rssfeed">\n];
+
+ my $i =0;
+ my $desc;
+ my $title;
+ my $hs = HTML::Strip->new();
+
+ # print the channel items
+ foreach my $item (@{$rss->{'items'}}[0 .. 15]) {
+ next unless defined($item->{'title'}) && defined($item->{'link'});
+ $title = $item->{'title'};
+ $desc = substr($hs->parse($item->{'description'}),0, 100);
+
+ # Wed, 03 Sep 2008 06:58
+ my $date = DateTime::Format::Mail->parse_datetime($item->{pubDate})->strftime('%a, %d %b %Y %R');
+
+ print $fh "<blockquote class=\"bluebox\">\n";
+ print $fh qq[<h3>$date</h3>\n];
+ print $fh qq[<h4>$title</h4>\n];
+ print $fh qq{<p class="update">$desc</p>\n};
+ print $fh "</blockquote>\n";
+ }
+
+ print $fh "</div>";
+
+ close($fh) || die "Couldn't close $filename: $!\n";
+
+ move($filename, $output);
+
+}
+
+
+
+
+
+
--- /dev/null
+++ bin/rss.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+/home/mbsd/bin/rss2htmlsum.pl http://www.justjournal.com/users/mbsd/rss /home/mbsd/docs/mbsdblogsum.inc
+/home/mbsd/bin/rss2html.pl http://www.justjournal.com/users/mbsd/rss /home/mbsd/docs/mbsdblog.inc
+/home/mbsd/bin/rss2htmlsum.pl http://cia.vc/stats/project/midnightbsd/.rss /home/mbsd/docs/cvslistsum.inc
+/home/mbsd/bin/rss2html.pl http://cia.vc/stats/project/midnightbsd/.rss /home/mbsd/docs/cvslist.inc
--- /dev/null
+++ bin/rss2htmlsum.pl
@@ -0,0 +1,91 @@
+#!/usr/bin/perl -w
+# rss2html - converts an RSS file to HTML
+# It take one argument, either a file on the local system,
+# or an HTTP URL like http://slashdot.org/slashdot.rdf
+# by Jonathan Eisenzopf. v1.0 19990901
+# Copyright (c) 1999 Jupitermedia Corp. All Rights Reserved.
+# See http://www.webreference.com/perl for more information
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# INCLUDES
+use strict;
+use XML::RSS;
+use LWP::Simple;
+use HTML::Strip;
+use DateTime::Format::Mail;
+use File::Temp qw(tempfile);
+use File::Copy qw(move);
+
+
+# MAIN
+# check for command-line argument
+die "Usage: rss2html.pl (<RSS file> | <URL>) <output file>\n" unless @ARGV == 2;
+
+# get the command-line argument
+my ($input, $output) = @ARGV;
+
+# create new instance of XML::RSS
+my $rss = XML::RSS->new;
+
+# argument is a URL
+if ($input=~ /http:/i) {
+ my $content = get($input) || die "Couldn't fetch $input\n";
+ # parse the RSS content
+ $rss->parse($content);
+
+# argument is a file
+} else {
+ die qq[File "$input" does't exist.\n] unless -e $input;
+ # parse the RSS file
+ $rss->parsefile($input);
+}
+
+# print the HTML channel
+print_html($rss, $output);
+
+# SUBROUTINES
+sub print_html {
+ my ($rss, $output) = @_;
+
+ my ($fh, $filename) = tempfile() or die "Couldn't make tmpfile: $!\n";
+
+ print "FILENAME: $filename, output: $output\n";
+
+ print $fh qq[<div class="rssfeed">\n];
+
+ my $i =0;
+ my $desc;
+ my $hs = HTML::Strip->new();
+
+ # print the channel items
+ foreach my $item (@{$rss->{'items'}}[0 .. 1]) {
+ next unless defined($item->{'title'}) && defined($item->{'link'});
+ $desc = substr($hs->parse($item->{'description'}),0, 100);
+
+ # Wed, 03 Sep 2008 06:58
+ my $date = DateTime::Format::Mail->parse_datetime($item->{pubDate})->strftime('%a, %d %b %Y %R');
+
+ print $fh "<blockquote>\n";
+ print $fh qq[<p class="date">$date</p>\n];
+ print $fh qq{<p class="update">$desc</p>\n};
+ print $fh qq{<p class="more"><a href="news/">Read more...</a></p>\n};
+ print $fh "</blockquote>\n";
+ }
+
+ print $fh "</div>";
+
+ close($fh) || die "Couldn't close $filename: $!\n";
+
+ move($filename, $output);
+
+}
+
+
+
+
+
+
More information about the Midnightbsd-cvs
mailing list