7 use Data::Dump qw/dump/;
17 # Bib-1 @and @and @and @and @and @and @and @or
23 # @attr 1=21 subject-holding
24 # @attr 1=12 control-no
25 # @attr 1=1007 standard-id
28 # LCC - Klasifikacija Kongresne knjižnice
29 # LCN - Signatura Kongresne knjižnice
30 # DDC - Deweyjeva klasifikacija
35 # SRS - Nakladnička cjelina
38 # WTI - Riječi u polju naslova
39 # WAU - Riječi u polju autora
40 # WPE - Riječi u polju individualnog autora
41 # WCO - Riječi u polju korporativnog autora
42 # WME - Riječi u polju sastanka
43 # WUT - Riječi u polju jedinstvenog naslova
44 # WPL - Riječi u polju mjesta izdavanja
45 # WPU - Riječi u polju nakladnika
46 # WSU - Riječi u polju predmetnica
47 # WSM - Riječi u predmetnicama MeSH-a
48 # WST - Riječi u polju status
49 # WGA - Riječi u geografskim odrednicama
50 # WYR - Godina izdavanja
67 my ( $self, $query ) = @_;
69 die "need query" unless defined $query;
71 $session_id ||= int rand(1000000000);
72 # FIXME allocate session just once
73 my $url = 'http://katalog.nsk.hr/F?RN=' . $session_id;
74 # fake JavaScript code on page which creates random session
78 my $mech = $self->{mech} || die "no mech?";
81 diag "advanced search";
83 $mech->follow_link( url_regex => qr/find-c/ );
85 my $database = $self->{database};
87 if ( $mech->content =~ m{Requested library is unavailable at the moment} ) {
88 warn "ERROR: default database not available, try to swith to $database\n";
90 $mech->follow_link( url_regex => qr/local_base=$database/i );
91 diag "re-try advanced search";
92 $mech->follow_link( url_regex => qr/find-c/ );
95 diag "submit search [$query] on ", $self->{database};
100 'ccl_term' => $query,
101 'local_base' => $self->{database},
106 if ( $mech->content =~ m{ukupno\s+(\d+).*do\s+(\d+)}s ) { # FIXME Many results in Crotian
108 $hits = $2 if $2 && $2 < $1; # correct for max. results
109 } elsif ( $mech->content =~ m{(\d+)\s+od\s+(\d+)}s ) { # FIXME single result in Croatian
112 diag "get't find results in ", $mech->content;
116 diag "got $hits results, get first one";
118 $mech->follow_link( url_regex => qr/set_entry=000001/ );
120 diag "in MARC format";
122 $mech->follow_link( url_regex => qr/format=001/ );
124 return $self->{hits} = $hits;
128 our ( $hash, $marc );
131 my ($self,$format) = @_;
135 my $mech = $self->{mech} || die "no mech?";
137 #warn "## ", $mech->content;
139 if ( $mech->content =~ m{Zapis\s+(\d+)}s ) {
145 $marc = MARC::Record->new;
146 $marc->encoding('utf-8');
149 my $html = $mech->content;
153 $v =~ s/\Q \E/ /gs;
164 warn "$f not numeric!";
168 if ( $v !~ s/^\|// ) { # no subfields
169 $marc->add_fields( $f, $v );
170 warn "## ++ ", dump( $f, $v );
174 my ($i1,$i2) = (' ',' ');
175 ($i1,$i2) = ($2,$3) if $f =~ s/^(...)(.)?(.)?/$1/;
176 my @sf = split(/\|/, $v);
177 @sf = map { s/^(\w)\s+//; { $1 => $_ } } @sf;
178 #warn "## sf = ", dump(@sf);
179 $marc->add_fields( $f, $i1, $i2, @sf );
180 warn "## ++ ", dump( $f, $i1, $i2, @sf );
183 $html =~ s|<tr>\s*<td class=td1 id=bold[^>]*>(.+?)</td>\s*<td class=td1>(.+?)</td>|field($1,$2)|ges;
184 diag "# hash ",dump($hash);
185 diag "# marc ", $marc->as_formatted;
187 my $id = $hash->{SYS} || die "no SYS";
189 $self->save_marc( "$id.marc", $marc->as_usmarc );
191 if ( $nr < $self->{hits} ) {
193 diag "follow link to next record $nr";
194 $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
199 die "can't fetch COMARC format from ", $mech->content;