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_marc $nr [$id] $format";
132 $comarc =~ s{</?b>}{}gs;
133 $comarc =~ s{<font[^>]*>}{<s>}gs;
134 $comarc =~ s{</font>}{<e>}gs;
136 open(my $out, '>:utf8', "comarc/$id");
142 my $marc = MARC::Record->new;
144 $comarc =~ s/[\r\n]+\s{5}//gs; # join continuation lines
145 warn "## comarc join: $comarc\n";
147 foreach my $line ( split(/[\r\n]+/, $comarc) ) {
149 if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
154 my ( $f, $i1, $i2 ) = ( $1, $2, $3 );
157 our $ignored = undef;
160 my ($format,$f,$sf,$v) = @_;
164 if ( $format =~ m/unimarc/i ) {
165 push @{ $out->{ $f } }, ( $sf, $v );
166 } elsif ( $format =~ m/marc/ ) {
167 if ( my $m = $cobiss_marc21->{$f}->{$sf} ) {
168 push @{ $out->{ $m->[0] } }, ( $m->[1], $v );
173 return ''; # fix warning
176 $l =~ s{<s>(\w)<e>([^<]+)}{sf_us($format,$f,$1, $2)}ges;
178 diag "[$format] $line -> ",dump( $out ) if $out;
180 foreach my $f ( keys %$out ) {
181 $marc->add_fields( $f, $i1, $i2, @{ $out->{$f} } );
186 $self->save_marc( "$id.$format", $marc->as_usmarc );
187 diag $marc->as_formatted;
189 if ( $nr < $self->{hits} ) {
190 warn "# fetch next result";
192 $mech->follow_link( url_regex => qr/rec=$nr/ );
194 warn "# no more results";
197 return $marc->as_usmarc;
199 die "can't fetch COMARC format from ", $mech->content;