sub usemap {{
4 => 'WTI',
- 1003 => 'WTI',
- 16 => 'CU',
- 21 => 'SU',
-# 12 => '',
+ 1003 => 'AUT',
+ 16 => 'DDC',
+ 21 => 'SUB',
+ 12 => 'LCN',
# 1007 => '',
-# 1016 => '',
+ 1016 => 'WRD',
}};
+our $session_id;
sub search {
my ( $self, $query ) = @_;
die "need query" unless defined $query;
- my $url = 'http://161.53.240.197:8991/F?RN=' . int rand(1000000000);
+ $session_id ||= int rand(1000000000);
+ # FIXME allocate session just once
+ my $url = 'http://161.53.240.197:8991/F?RN=' . $session_id;
# fake JavaScript code on page which creates random session
diag "get $url";
$mech->follow_link( url_regex => qr/find-c/ );
-diag "submit search $query";
+ my $database = $self->{database};
+
+ if ( $mech->content =~ m{Requested library is unavailable at the moment} ) {
+ warn "ERROR: default database not available, try to swith to $database\n";
+ $self->save_content;
+ $mech->follow_link( url_regex => qr/local_base=$database/i );
+ diag "re-try advanced search";
+ $mech->follow_link( url_regex => qr/find-c/ );
+ }
+
+diag "submit search [$query] on ", $self->{database};
+
$mech->submit_form(
fields => {
'ccl_term' => $query,
+ 'local_base' => $self->{database},
},
);
$mech->follow_link( url_regex => qr/format=001/ );
- return $hits;
+ return $self->{hits} = $hits;
}
sub field {
my ( $f, $v ) = @_;
$v =~ s/\Q \E/ /gs;
+ $v =~ s/\s+$//gs;
warn "## $f\t$v\n";
$hash->{$f} = $v;
my $id = $hash->{SYS} || die "no SYS";
- $self->save_marc( $id, $marc->as_usmarc );
-
- $nr++;
+ $self->save_marc( "$id.marc", $marc->as_usmarc );
- $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
+ if ( $nr < $self->{hits} ) {
+ $nr++;
+ diag "follow link to next record $nr";
+ $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
+ }
- return $marc->as_usmarc;
+ return $id;
} else {
die "can't fetch COMARC format from ", $mech->content;
}