7 |
|
|
8 |
my $ua = LWP::UserAgent->new; |
my $ua = LWP::UserAgent->new; |
9 |
|
|
10 |
|
our $cache; |
11 |
|
|
12 |
sub item { |
sub item { |
13 |
my ( $class, $client, $item ) = @_; |
my ( $class, $client, $item ) = @_; |
14 |
|
|
15 |
my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item; |
my $html; |
16 |
|
my $status = 200; |
17 |
|
|
18 |
|
if ( $html = $cache->{$item} ) { |
19 |
|
|
20 |
|
warn "# koha item $item from cache\n"; |
21 |
|
|
22 |
|
} else { |
23 |
|
|
24 |
|
my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item; |
25 |
|
|
26 |
|
my $response = $ua->get( $url ); |
27 |
|
|
28 |
|
if ($response->is_success) { |
29 |
|
|
30 |
|
$html = $response->content; |
31 |
|
$html =~ s{<head>.+?<h1>}{<h1>}s; |
32 |
|
$html =~ s{<div class="content_set">.+$}{}s; |
33 |
|
$html =~ s{</?img[^>]+>}{}g; |
34 |
|
|
35 |
|
$cache->{$item} = $html; |
36 |
|
|
37 |
|
} else { |
38 |
|
|
39 |
my $response = $ua->get( $url ); |
$html = qq{Can't load $item } . $response->status_line; |
40 |
|
# $status = 404; |
41 |
|
|
42 |
my $html = $response->content; |
} |
43 |
$html =~ s{<head>.+?<h1>}{<h1>}s; |
} |
|
$html =~ s{<div class="content_set">.+$}{}s; |
|
44 |
|
|
45 |
my $len = length($html); |
my $len = length($html); |
46 |
|
|
47 |
warn "# koha item $item [$len]\n"; |
warn "# koha item $item [$len]\n"; |
48 |
|
|
49 |
$client->write( |
$client->write( |
50 |
'HTTP/1.1 ' . $response->status_line . "\r\n" . |
"HTTP/1.1 $status OK\r\n" . |
51 |
"Content-Type: text/html\r\n" . |
"Content-Type: text/html\r\n" . |
52 |
"Content-length: $len\r\n" . |
"Content-length: $len\r\n" . |
53 |
"Connection: close\r\n" . |
"Connection: close\r\n" . |