Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/perl
- # Convert rss to text - rss2txt.pl
- #
- # Usage : rss2txt.pl <RSS file> > textfile.txt
- #
- # 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.
- #
- # Modified by Paul Harvey to output each entry to a new file.
- use strict;
- die "Usage: rss2txt.pl <RSS file> > textfile.txt\n" unless @ARGV == 1;
- BEGIN { push @INC,'.'; }
- use XML::RSS;
- use LWP::Simple;
- my $folder = "feedtext";
- my $rss = new XML::RSS;
- my $content;
- my $arg = shift;
- if ($arg =~ /http:/i) {
- $content = get($arg);
- die "Error: Cannot get $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 $@;
- }
- mkdir $folder;
- for my $item (@{$rss->{'items'}}) {
- my $filename = &trim($item->{'title'});
- my $itemdesc = &trim($item->{'description'});
- my $text;
- $text .= qq|$filename\n|;
- $text .= qq|$itemdesc\n|;
- open (OUTFILE, ">$folder/$filename") or die "Couldn't open \"$filename\": $!";
- print OUTFILE $text;
- close OUTFILE;
- }
- exit;
- # ---------------------------------------------------------------------------- #
- sub trim{
- my $value = $_[0];
- if ($value) {
- $value =~ s/^\s+//;
- $value =~ s/\s+$//;
- }
- return $value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement