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 ) {
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 ])}{} ) {
152 our @f = ( $1, $2, $3 );
155 if ( $format eq 'unimarc' ) {
157 diag dump(@f), "line: $line";
162 $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf_uni($1, $2)}ges;
163 diag "f:", dump(@f), " left: |$line|";
164 $marc->add_fields( @f );
166 } elsif ( $format eq 'usmarc' ) {
168 my ( $f, $i1, $i2 ) = @f;
174 if ( my $m = $cobiss_marc21->{$f}->{$sf} ) {
175 push @{ $out->{ $m->[0] } }, ( $m->[1], $v );
179 $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf_us($f,$1, $2)}ges;
181 diag "converted marc21 ",dump( $out );
183 foreach my $f ( keys %$out ) {
184 $marc->add_fields( $f, $i1, $i2, @{ $out->{$f} } );
190 $self->save_marc( $id, $marc->as_usmarc );
191 diag $marc->as_formatted;
194 $mech->follow_link( url_regex => qr/rec=$nr/ );
196 return $marc->as_usmarc;
198 die "can't fetch COMARC format from ", $mech->content;