9 |
|
|
10 |
our $cache; |
our $cache; |
11 |
|
|
12 |
|
use HTML::Query qw/Query/; |
13 |
|
use File::Slurp; |
14 |
|
use Encode qw/decode/; |
15 |
|
use Data::Dump qw/dump/; |
16 |
|
|
17 |
sub item { |
sub item { |
18 |
my ( $class, $client, $item ) = @_; |
my ( $class, $client, $item ) = @_; |
19 |
|
|
20 |
my $html; |
my $html; |
21 |
my $status = 200; |
my $status = 200; |
22 |
|
|
23 |
|
my $path = "cache/$item.html"; |
24 |
|
|
25 |
if ( $html = $cache->{$item} ) { |
if ( $html = $cache->{$item} ) { |
26 |
|
|
27 |
warn "# koha item $item from cache\n"; |
warn "# koha item $item from cache\n"; |
28 |
|
|
29 |
|
} elsif ( 0 && -e $path ) { # FIXME enable |
30 |
|
|
31 |
|
$html = $cache->{$item} = read_file( $path ); |
32 |
|
|
33 |
} else { |
} else { |
34 |
|
|
35 |
my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item; |
my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item; |
39 |
if ($response->is_success) { |
if ($response->is_success) { |
40 |
|
|
41 |
$html = $response->content; |
$html = $response->content; |
42 |
$html =~ s{<head>.+?<h1>}{<h1>}s; |
|
43 |
$html =~ s{<div class="content_set">.+$}{}s; |
write_file( "cache/$item.koha.html", $html ); |
44 |
$html =~ s{</?img[^>]+>}{}g; |
|
45 |
|
warn "## size before: ", length( $html ); |
46 |
|
|
47 |
|
$html = decode( 'utf-8', $html ); |
48 |
|
my $q = Query( text => $html, 'div.container' ) |
49 |
|
|| die; |
50 |
|
$html = $q->as_HTML->[0]; |
51 |
|
|
52 |
|
warn "## size after: ", length( $html ), dump( $html ); |
53 |
|
|
54 |
$cache->{$item} = $html; |
$cache->{$item} = $html; |
55 |
|
write_file( $path, $html ); |
56 |
|
|
57 |
} else { |
} else { |
58 |
|
|