aboutsummaryrefslogtreecommitdiff
path: root/run/perlmonks
blob: 499fe6125bf9d21f1742985f5f138885be120d8a (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
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl

use strict;
use warnings;

use HTML::Entities;
use LWP::UserAgent ();
use Time::Piece;
use XML::LibXML;

# Retrieve XML
my $ua = LWP::UserAgent->new(timeout => 15);
$ua->ssl_opts(verify_hostname => 0);
$ua->env_proxy;
$ua->agent('');
my $u = 'https://www.perlmonks.org/?node_id=30175';
my $r = $ua->get($u);
die $r->status_line if not $r->is_success;

# Parse XML
my $dom = XML::LibXML->load_xml(string => $r->decoded_content);

# Print HTML representation of each node
my $i;
my @nodes =
	sort { $b->[1] <=> $a->[1] }
	map { [$_, Time::Piece->strptime(($_->findnodes('./@createtime'))[0]->to_literal, '%Y%m%d%H%M%S')] }
	$dom->findnodes('/NEWESTNODES/NODE');
for (@nodes) {
	my ($node, $time) = @$_;
	my $d = $time->strftime('%a, %e %B %Y %H:%M:%S UTC');
	my $f = encode_entities(($node->findnodes('./@authortitle'))[0]->to_literal);
	(my $s = encode_entities $node->to_literal) =~ s/^\s+|\s+$//;
	my $l = 'https://www.perlmonks.org/?node_id=' . ($node->findnodes('./@node_id'))[0]->to_literal;

	next if $s eq $f; # Skip home nodes
	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
	last if ++$i >= 5;
}