-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss_parse.pl
55 lines (39 loc) · 1.1 KB
/
rss_parse.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use Useful;
# Copyright: Judita Preiss
# Date of creation: 11 September 2011
use XML::RSS::Parser::Lite;
use LWP::UserAgent;
# This program attempts to avoid the problems generated by the Perl
# XML::RSS module: this module cannot cope with even very simple RSS
# errors and causes failure. This program therefore is allowed to fail
# if the module fails and the wrapper picks up failure from this
# program.
(scalar(@ARGV) == 2) or die "Args: type url\n";
$type = $ARGV[0];
sub read_file {
my ($html, $file);
(scalar(@_) == 1) or die "read_file: file\n";
$file = $_[0];
open(INPUT, $file) or die "Can't open $file: $!\n";
$html = "";
while($line = <INPUT>){
chomp($line);
$html .= " " . $line;
}
close(INPUT);
$html = remove_multiple_spaces($html);
return $html;
}
if($type eq "file"){
my $rss = new XML::RSS::Parser::Lite;
$html = read_file($ARGV[1]);
$rss->parse($html);
}
elsif($type eq "url"){
my $rss = new XML::RSS::Parser::Lite;
my $html = get_url($ARGV[1]);
$rss->parse($html);
}
else{
die "Unexpected type: $type\n";
}