diff options
author | John Ankarström <john@ankarstrom.se> | 2021-05-07 00:26:03 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-05-07 00:26:03 +0200 |
commit | 73e1da5d04e27e56b584ce6dce4eb086eb7413fe (patch) | |
tree | 27b18a731c904f22c09d9d2f118cc77109a8dc49 | |
parent | c5abd34524f4adc51872d3d685398398fb18d9c4 (diff) | |
download | perlisdead-73e1da5d04e27e56b584ce6dce4eb086eb7413fe.tar.gz |
Sort PerlMonks nodes
-rwxr-xr-x | run/perlmonks | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/run/perlmonks b/run/perlmonks index 1f1e5b3..53e9583 100755 --- a/run/perlmonks +++ b/run/perlmonks @@ -12,8 +12,8 @@ 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); +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 @@ -21,8 +21,13 @@ 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 @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 = ($node->findnodes('./@authortitle'))[0]->to_literal; (my $s = $node->to_literal) =~ s/^\s+|\s+$//; next if $s eq $f; # Skip home nodes |