9 binmode STDOUT, ':utf8';
12 '010' => { a => [ '020', 'a' ] },
17 205 => { a => [ 250 , 'a' ] },
33 our $mech = WWW::Mechanize->new();
42 # Bib-1 @and @and @and @and @and @and @and @or
48 # @attr 1=21 subject-holding
49 # @attr 1=12 control-no
50 # @attr 1=1007 standard-id
54 8 => 'BN', # FIXME check
55 7 => 'SN', # FIXME check
72 my ( $self, $query ) = @_;
74 die "need query" unless defined $query;
76 my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en';
84 $mech->follow_link( text_regex => qr/union/ );
86 diag "switch to advanced form (select)";
88 $mech->follow_link( url_regex => qr/mode=3/ );
90 diag "submit search $query";
99 if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
102 diag "get't find results in ", $mech->content;
106 diag "got $hits results, get first one";
108 $mech->follow_link( url_regex => qr/ukaz=DISP/ );
110 diag "in COMARC format";
112 $mech->follow_link( url_regex => qr/fmt=13/ );
121 if ( $mech->content =~ m{<pre>\s*(.+?(\d+)\.\s+ID=(\d+).+?)\s*</pre>}s ) {
127 diag "fetch_marc $nr [$id]";
129 $comarc =~ s{</?b>}{}gs;
130 $comarc =~ s{<font[^>]*>}{<s>}gs;
131 $comarc =~ s{</font>}{<e>}gs;
133 open(my $out, '>:utf8', "comarc/$id");
139 my $marc = MARC::Record->new;
141 foreach my $line ( split(/[\r\n]+/, $comarc) ) {
143 if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
148 our @f = ( $1, $2, $3 );
149 sub sf { push @f, @_; }
150 $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf($1, $2)}ges;
151 diag "f:", join('|', @f), " left: |$line|";
152 $marc->add_fields( @f );
156 open(my $out, '>:utf8', "marc/$id");
157 print $out $marc->as_usmarc;
160 diag $marc->as_formatted;
163 $mech->follow_link( url_regex => qr/rec=$nr/ );
165 return $marc->as_usmarc;
167 die "can't fetch COMARC format from ", $mech->content;