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://mksun.mkutup.gov.tr/F?RN=' . $session_id . '&func=find-c-0';
74 # fake JavaScript code on page which creates random session
76 diag "advanced search $url";
78 my $mech = $self->{mech} || die "no mech?";
81 diag "submit search [$query]";
90 if ( $mech->content =~ m{Toplam\s+(\d+)} ) { # FIXME Many results in Crotian
93 diag "get't find results in ", $mech->content;
97 diag "got $hits results, get first one";
99 $mech->follow_link( url_regex => qr/set_entry=000001/ );
101 diag "in MARC format";
103 $mech->follow_link( url_regex => qr/format=001/ );
105 return $self->{hits} = $hits;
109 our ( $hash, $marc );
112 my ($self,$format) = @_;
116 my $mech = $self->{mech} || die "no mech?";
118 #warn "## ", $mech->content;
120 if ( $mech->content =~ m{kay.ttan\s+(\d+)}s ) {
126 $marc = MARC::Record->new;
127 $marc->encoding('utf-8');
130 my $html = $mech->content;
137 return if $f >= 900; # skip local fields
139 $v =~ s/\Q \E/ /gs;
141 warn "## $f\t[$v]\n";
150 warn "$f not numeric!";
154 if ( $v !~ s/^\|// ) { # no subfields
155 $marc->add_fields( $f, $v );
156 warn "## ++ ", dump( $f, $v );
160 my ($i1,$i2) = (' ',' ');
161 ($i1,$i2) = ($2,$3) if $f =~ s/^(...)(.)(.)?/$1/;
162 my @sf = split(/\|/, $v);
163 @sf = map { s/^(\w)\s+//; { $1 => $_ } } @sf;
164 #warn "## sf = ", dump(@sf);
168 $marc->add_fields( $f, $i1, $i2, @sf );
169 warn "## ++ ", dump( $f, $i1, $i2, @sf );
171 warn "SKIP: $@" if $@;
174 $html =~ s|<tr>\s*?<td[^>]*class=td1[^>]*>(.+?)</td>\s*?<td class=td1>(.+?)</td>\s*</tr>|field($1,$2)|ges;
175 diag "# hash ",dump($hash);
176 diag "# marc ", $marc->as_formatted;
178 my $id = $hash->{SYS} || die "no SYS";
180 $self->save_marc( "$id.marc", $marc->as_usmarc );
182 if ( $nr < $self->{hits} ) {
184 diag "follow link to next record $nr";
185 $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
190 die "can't fetch " . __PACKAGE__ . " format from ", $mech->content;