Commit b72456b0 authored by Luc Didry's avatar Luc Didry

Fix #2 - Add toot cache

parent 33e3c982
Pipeline #16905 canceled with stage
in 1 minute and 6 seconds
*.swp
local/*
public/*
cache/*
......@@ -5,6 +5,7 @@ pages:
untracked: true
paths:
- local
- cache
script:
- carton install
- carton exec ./build.pl
......
......@@ -169,8 +169,9 @@ my $urls = c(@{$config->{urls}});
}
) if $config->{sort};
$urls = $urls->reverse if $config->{reverse};
## Create needed dir
## Create needed dirs
mkdir 'public/epub/OPS/text';
mkdir 'cache' unless -e 'cache';
# URLs processing
my $n = 0;
......@@ -186,10 +187,14 @@ $urls->each(
## Get only the pod's hostname and scheme
my $host = Mojo::URL->new($i)->path('');
my $res = $ua->get($i)->result;
if ($res->is_success) {
my $cache = (-e "cache/$id.html");
my $res;
$res = $ua->get($i)->result unless $cache;
if ($cache || $res->is_success) {
Mojo::File->new("cache/$id.html")->spurt(encode 'UTF-8', $res->dom->to_string) unless $cache;
## Get only the targeted toot, not the replies
my $dom = $res->dom->find('.entry-center .detailed-status')->first;
my $dom = ($cache) ? Mojo::DOM->new(decode('UTF-8', Mojo::File->new("cache/$id.html")->slurp)) : $res->dom;
$dom = $dom->find('.entry-center .detailed-status')->first;
## Get the content of the toot
my $content = $dom->find('.e-content')->first;
## Get the metadata (ie date and time) of the toot
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment