7 use Data::Dump qw/dump/;
18 # Bib-1 @and @and @and @and @and @and @and @or
24 # @attr 1=21 subject-holding
25 # @attr 1=12 control-no
26 # @attr 1=1007 standard-id
29 # LCC - Klasifikacija Kongresne knjižnice
30 # LCN - Signatura Kongresne knjižnice
31 # DDC - Deweyjeva klasifikacija
36 # SRS - Nakladnička cjelina
39 # WTI - Riječi u polju naslova
40 # WAU - Riječi u polju autora
41 # WPE - Riječi u polju individualnog autora
42 # WCO - Riječi u polju korporativnog autora
43 # WME - Riječi u polju sastanka
44 # WUT - Riječi u polju jedinstvenog naslova
45 # WPL - Riječi u polju mjesta izdavanja
46 # WPU - Riječi u polju nakladnika
47 # WSU - Riječi u polju predmetnica
48 # WSM - Riječi u predmetnicama MeSH-a
49 # WST - Riječi u polju status
50 # WGA - Riječi u geografskim odrednicama
51 # WYR - Godina izdavanja
68 my ( $self, $query ) = @_;
70 die "need query" unless defined $query;
72 $session_id ||= int rand(1000000000);
73 # FIXME allocate session just once
74 my $url = 'https://katalog.nsk.hr/F?RN=' . $session_id;
75 # fake JavaScript code on page which creates random session
79 my $mech = $self->{mech} || die "no mech?";
82 diag "advanced search";
84 $mech->follow_link( url_regex => qr/find-c/ );
86 my $database = $self->{database};
88 if ( $mech->content =~ m{Requested library is unavailable at the moment} ) {
89 warn "ERROR: default database not available, try to swith to $database\n";
91 $mech->follow_link( url_regex => qr/local_base=$database/i );
92 diag "re-try advanced search";
93 $mech->follow_link( url_regex => qr/find-c/ );
96 diag "submit search [$query] on ", $self->{database};
101 'ccl_term' => $query,
102 'local_base' => $self->{database},
107 if ( $mech->content =~ m{ukupno\s+(\d+).*do\s+(\d+)} ) { # FIXME Many results in Crotian
109 $hits = $2 if $2 && $2 < $1; # correct for max. results
110 } elsif ( $mech->content =~ m{(\d+)\s+od\s+(\d+)} ) { # FIXME single result in Croatian
113 diag "get't find results in ", $mech->content;
117 diag "got $hits results, get first one";
119 $mech->follow_link( url_regex => qr/set_entry=000001/ );
121 diag "in MARC format";
123 $mech->follow_link( url_regex => qr/format=001/ );
125 return $self->{hits} = $hits;
129 our ( $hash, $marc );
132 my ($self,$format) = @_;
136 my $mech = $self->{mech} || die "no mech?";
138 #warn "## ", $mech->content;
140 if ( $mech->content =~ m{Zapis\s+(\d+)}s ) {
146 $marc = MARC::Record->new;
147 $marc->encoding('utf-8');
150 my $html = $mech->content;
154 $v =~ s/\Q \E/ /gs;
165 warn "$f not numeric!";
169 if ( $v !~ s/^\|// ) { # no subfields
170 $marc->add_fields( $f, $v );
171 warn "## ++ ", dump( $f, $v );
175 my ($i1,$i2) = (' ',' ');
176 ($i1,$i2) = ($2,$3) if $f =~ s/^(...)(.)?(.)?/$1/;
179 my @sf = split(/\|/, $v);
180 @sf = map { s/^(\w)\s+//; { $1 => $_ } } @sf;
181 #warn "## sf = ", dump(@sf);
182 $marc->add_fields( $f, $i1, $i2, @sf );
183 warn "## ++ ", dump( $f, $i1, $i2, @sf );
186 $html =~ s|<tr>\s*<td class=td1 id=bold[^>]*>(.+?)</td>\s*<td class=td1>(.+?)</td>|field($1,$2)|ges;
187 diag "# hash ",dump($hash);
188 diag "# marc ", $marc->as_formatted;
190 my $id = $hash->{SYS} || die "no SYS";
192 $self->save_marc( "$id.marc", $marc->as_usmarc );
194 if ( $nr < $self->{hits} ) {
196 diag "follow link to next record $nr";
197 $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
202 die "can't fetch COMARC format from ", $mech->content;