aboutsummaryrefslogtreecommitdiff
path: root/run/perlmonks
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-05-06 18:21:15 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-05-06 18:21:15 +0200
commitdf484fd9b6640639c3a6098814b41628d02e5d54 (patch)
treebad0c9b4f01d383059937a95cabd48d6ed544473 /run/perlmonks
parent65f946b63b4786170702097288aa1c84bd8e8fa1 (diff)
downloadperlisdead-df484fd9b6640639c3a6098814b41628d02e5d54.tar.gz
Add perlmonks, irc nodes
Diffstat (limited to 'run/perlmonks')
-rw-r--r--run/perlmonks38
1 files changed, 38 insertions, 0 deletions
diff --git a/run/perlmonks b/run/perlmonks
new file mode 100644
index 0000000..1f1e5b3
--- /dev/null
+++ b/run/perlmonks
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use LWP::UserAgent ();
+use Time::Piece;
+use XML::LibXML;
+
+# Retrieve XML
+my $ua = LWP::UserAgent->new(timeout => 5);
+$ua->ssl_opts(verify_hostname => 0);
+$ua->env_proxy;
+$ua->agent('');
+my $a = 'https://www.perlmonks.org/?node_id=30175';
+my $r = $ua->get($a);
+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;
+for my $node ($dom->findnodes('/NEWESTNODES/NODE')) {
+ my $d = Time::Piece->strptime(($node->findnodes('./@createtime'))[0]->to_literal, '%Y%m%d%H%M%S')->strftime('%a, %e %B %Y %H:%M:%S UTC');
+ my $f = ($node->findnodes('./@authortitle'))[0]->to_literal;
+ (my $s = $node->to_literal) =~ s/^\s+|\s+$//;
+ next if $s eq $f; # Skip home nodes
+ my $l = 'https://www.perlmonks.org/?node_id=' . ($node->findnodes('./@node_id'))[0]->to_literal;
+ 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;
+}