7 use Data::Dump qw/dump/;
12 '010' => { a => [ '020', 'a' ] },
17 205 => { a => [ 250 , 'a' ] },
39 # Bib-1 @and @and @and @and @and @and @and @or
45 # @attr 1=21 subject-holding
46 # @attr 1=12 control-no
47 # @attr 1=1007 standard-id
51 8 => 'BN', # FIXME check
52 7 => 'SN', # FIXME check
64 my ( $self, $query ) = @_;
66 die "need query" unless defined $query;
68 my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en';
72 my $mech = $self->{mech} || die "no mech?";
79 $mech->follow_link( text_regex => qr/union/ );
81 diag "switch to advanced form (select)";
83 $mech->follow_link( url_regex => qr/mode=3/ );
85 diag "submit search $query";
94 if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
95 $self->{hits} = $hits = $1;
97 diag "get't find results in ", $mech->content;
101 diag "got $hits results, get first one";
103 $mech->follow_link( url_regex => qr/ukaz=DISP/ );
105 diag "in COMARC format";
107 $mech->follow_link( url_regex => qr/fmt=13/ );
114 my ($self,$format) = @_;
116 my $mech = $self->{mech} || die "no mech?";
118 $format ||= 'unimarc';
120 die "unknown format: $format" unless $format =~ m{(uni|us)marc};
124 if ( $mech->content =~ m{<pre>\s*(.+?(\d+)\.\s+ID=(\d+).+?)\s*</pre>}s ) {
130 diag "fetch $nr [$id] $format";
132 $markup =~ s{</?b>}{}gs;
133 $markup =~ s{<font[^>]*>}{<s>}gs;
134 $markup =~ s{</font>}{<e>}gs;
136 $markup =~ s/[\r\n]+\s{5}//gs; # join continuation lines
138 $self->save_marc( "$id.xml", $markup );
140 my $marc = MARC::Record->new;
141 my $comarc = MARC::Record->new;
143 foreach my $line ( split(/[\r\n]+/, $markup) ) {
145 if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
150 my ( $f, $i1, $i2 ) = ( $1, $2, $3 );
152 our $marc_map = undef;
153 our $comarc_map = undef;
154 our $ignored = undef;
161 push @{ $comarc_map->{ $f } }, ( $sf, $v );
162 if ( my $m = $cobiss_marc21->{$f}->{$sf} ) {
163 push @{ $marc_map->{ $m->[0] } }, ( $m->[1], $v );
167 return ''; # fix warning
170 $l =~ s{<s>(\w)<e>([^<]+)}{sf_parse($f,$1, $2)}ges;
172 diag "[$format] $line -> ",dump( $comarc_map, $marc_map ) if $comarc_map;
174 foreach my $f ( keys %$comarc_map ) {
175 $comarc->add_fields( $f, $i1, $i2, @{ $comarc_map->{$f} } );
178 foreach my $f ( keys %$marc_map ) {
179 $marc->add_fields( $f, $i1, $i2, @{ $marc_map->{$f} } );
184 $self->save_marc( "$id.marc", $marc->as_usmarc );
185 $self->save_marc( "$id.unimarc", $comarc->as_usmarc );
186 diag $marc->as_formatted;
188 if ( $nr < $self->{hits} ) {
189 warn "# fetch next result";
191 $mech->follow_link( url_regex => qr/rec=$nr/ );
193 warn "# no more results";
198 die "can't fetch COMARC format from ", $mech->content;