aboutsummaryrefslogtreecommitdiff
path: root/run/rss
blob: 1fdaf09091954a0957eb1a56e6baaaf0aa9584f8 (plain)
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
#!/usr/bin/perl

use strict;
use warnings;

use HTML::Entities;
use XML::Feed;
use Encode qw(decode encode);

my %feeds = (
	blogs => 'http://blogs.perl.org/atom.xml',
	reddit => 'https://www.reddit.com/r/perl/.rss',
	cpan => 'https://metacpan.org/feed/recent',
);
(my $name = $0) =~ s,.*/,,;

my $feed = XML::Feed->parse(URI->new($feeds{$name}))
	or die XML::Feed->errstr;

# Sort entries
my @entries = sort { $b->issued <=> $a->issued } $feed->entries;

# Print summary of five latest entries
for my $entry (@entries[0..4]) {
	my $d = $entry->issued->strftime('%a, %e %B %Y %H:%M:%S UTC');
	my $f = encode_entities decode('utf8', $entry->author);
	my $s = encode_entities decode('utf8', $entry->title);
	my $l = encode_entities $entry->link;
	print <<HTML
<div class="entry">
<div class="date">Date: $d</div>
<div class="from">From: $f</div>
<div class="subject"><a href="$l">$s</a></div>
</div>
HTML
}