store hits and don't try to download more records
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 23 Oct 2010 13:44:31 +0000 (15:44 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 23 Oct 2010 13:44:31 +0000 (15:44 +0200)
COBISS.pm

index 81b532e..7c50f0d 100644 (file)
--- a/COBISS.pm
+++ b/COBISS.pm
@@ -92,7 +92,7 @@ diag "submit search $query";
 
        $hits = 0;
        if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
-               $hits = $1;
+               $self->{hits} = $hits = $1;
        } else {
                diag "get't find results in ", $mech->content;
                return;
@@ -190,8 +190,13 @@ warn "## comarc join: $comarc\n";
                $self->save_marc( $id, $marc->as_usmarc );
                diag $marc->as_formatted;
 
-               $nr++;
-               $mech->follow_link( url_regex => qr/rec=$nr/ );
+               if ( $nr < $self->{hints} ) {
+                       warn "# fetch next result";
+                       $nr++;
+                       $mech->follow_link( url_regex => qr/rec=$nr/ );
+               } else {
+                       warn "# no more results";
+               }
 
                return $marc->as_usmarc;
        } else {