-
Notifications
You must be signed in to change notification settings - Fork 50
/
fetch-recent-blog-posts.pl
executable file
·36 lines (30 loc) · 1.22 KB
/
fetch-recent-blog-posts.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
#!/usr/bin/env perl
use Mojo::UserAgent;
use Mojo::JSON qw/encode_json/;
use Mojo::File qw/path/;
use Mojo::Util qw/xml_escape/;
my $tx = Mojo::UserAgent->new->get("https://planet.raku.org/atom.xml");
if ( my $err = $tx->error ) {
warn $err->{code} ? "ERROR: $err->{code} response: $err->{message}"
: "Connection error: $err->{message}";
exit;
}
my $j = $tx->res->dom->find("entry")->grep(sub {
# Hackish fix to get rid of comment entries from medium.com.
# Only articles appear to have `category` elements, so if we detect
# an entry from medium.com, ensure it also has `category` element
$_->at('link')->{href} =~ m{^https://medium\.com}
? $_->find('category')->each
: 1
})->map(sub{
# Look for text/html links and use the first without it if we don't find any
my $link = $_->at('link[type="text/html"]:not([rel="replies"])')
// $_->at('link:not([rel="replies"])');
+{
title => xml_escape($_->at("title")->all_text),
link => xml_escape($link->{href}),
}
})->to_array;
path('online/recent-blog-posts.json')->spurt(encode_json([@$j[0..6]]));
print "Successfully wrote new blog posts\n";
exit;