/
check_feed.pl
57 lines (47 loc) · 1.87 KB
/
check_feed.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
56
use strict;
use warnings;
use v5.10;
=head1 DESCRIPTION
Given a URL of an Atom or RSS feed or a filename of an already downloaded
feed, this script will try to parse it and print out what it understands
from the feed.
=cut
use XML::Feed;
my $src = shift;
die "Usage: $0 FILE|URL\n" if not $src;
my $source = $src;
if ($src =~ m{^https?://}) {
$source = URI->new($src);
} else {
if (not -f $source) {
die "'$source' does not look like a URL and it does not exist on the file-system either.\n";
}
}
my $feed = XML::Feed->parse( $source ) or die XML::Feed->errstr;
say 'Title: ' . ($feed->title // '');
say 'Tagline: ' . ($feed->tagline // '');
say 'Format: ' . ($feed->format // '');
say 'Author: ' . ($feed->author // '');
say 'Link: ' . ($feed->link // '');
say 'Base: ' . ($feed->base // '');
say 'Language: ' . ($feed->language // '');
say 'Copyright: ' . ($feed->copyright // '');
say 'Modified: ' . ($feed->modified // ''); # DateTime object
say 'Generator: ' . ($feed->generator // '');
for my $entry ($feed->entries) {
say '';
say ' Link: ' . ($entry->link // '');
say ' Author: ' . ($entry->author // '');
say ' Title: ' . ($entry->title // '');
say ' Caregory: ' . ($entry->category // '');
say ' Id: ' . ($entry->id // '');
say ' Issued: ' . ($entry->issued // ''); # DateTime object
say ' Modified: ' . ($entry->modified // ''); # DateTime object
say ' Lat: ' . ($entry->lat // '');
say ' Long: ' . ($entry->long // '');
say ' Format: ' . ($entry->format // '');
say ' Tags: ' . ($entry->tags // '');
say ' Enclosure: ' . ($entry->enclosure // '');
say ' Summary: ' . ($entry->summary->body // '');
say ' Content: ' . ($entry->content->body // '');
}