10 binmode STDOUT, ':utf8';
13 '010' => { a => [ '020', 'a' ] },
18 205 => { a => [ 250 , 'a' ] },
34 our $mech = WWW::Mechanize->new();
43 # Bib-1 @and @and @and @and @and @and @and @or
49 # @attr 1=21 subject-holding
50 # @attr 1=12 control-no
51 # @attr 1=1007 standard-id
55 8 => 'BN', # FIXME check
56 7 => 'SN', # FIXME check
73 my ( $self, $query ) = @_;
75 die "need query" unless defined $query;
77 my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en';
85 $mech->follow_link( text_regex => qr/union/ );
87 diag "# switch to advanced form (select)";
91 $mech->follow_link( url_regex => qr/mode=3/ );
93 diag "# submit search $query";
102 if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
105 diag "get't find results in ", $mech->content;
109 diag "# got $hits results, get first one";
111 $mech->follow_link( url_regex => qr/ukaz=DISP/ );
113 diag "# in COMARC format";
115 $mech->follow_link( url_regex => qr/fmt=13/ );
124 if ( $mech->content =~ m{<pre>\s*(.+?(\d+\.)\s+ID=(\d+).+?)\s*</pre>}s ) {
130 diag "# fetch_marc $nr [$id]";
132 $comarc =~ s{</?b>}{}gs;
133 $comarc =~ s{<font[^>]*>}{<s>}gs;
134 $comarc =~ s{</font>}{<e>}gs;
136 write_file "comarc/$id", $comarc;
140 my $marc = MARC::Record->new;
142 foreach my $line ( split(/[\r\n]+/, $comarc) ) {
145 if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
151 sub sf { push @f, @_; }
152 $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf($1, $2)}ges;
153 diag "# f:", join('|', @f), " left: |$line|";
154 $marc->add_fields( @f );
158 open(my $out, '>:utf8', "marc/$id");
159 print $out $marc->as_usmarc;
162 diag $marc->as_formatted;
164 return $marc->as_usmarc;
166 die "can't fetch COMARC format from ", $mech->content;