/[meteor]/trunk/Meteor/Koha.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Meteor/Koha.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 78 by dpavlin, Sat Mar 28 20:53:20 2009 UTC revision 79 by dpavlin, Sun Mar 29 00:11:48 2009 UTC
# Line 9  my $ua = LWP::UserAgent->new; Line 9  my $ua = LWP::UserAgent->new;
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;
# Line 28  sub item { Line 39  sub 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    

Legend:
Removed from v.78  
changed lines
  Added in v.79

  ViewVC Help
Powered by ViewVC 1.1.26