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)";
89 $mech->follow_link( url_regex => qr/mode=3/ );
91 diag "submit search $query";
100 if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
103 diag "get't find results in ", $mech->content;
107 diag "got $hits results, get first one";
109 $mech->follow_link( url_regex => qr/ukaz=DISP/ );
111 diag "in COMARC format";
113 $mech->follow_link( url_regex => qr/fmt=13/ );
122 if ( $mech->content =~ m{<pre>\s*(.+?(\d+\.)\s+ID=(\d+).+?)\s*</pre>}s ) {
128 diag "fetch_marc $nr [$id]";
130 $comarc =~ s{</?b>}{}gs;
131 $comarc =~ s{<font[^>]*>}{<s>}gs;
132 $comarc =~ s{</font>}{<e>}gs;
134 write_file "comarc/$id", $comarc;
138 my $marc = MARC::Record->new;
140 foreach my $line ( split(/[\r\n]+/, $comarc) ) {
142 if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
147 our @f = ( $1, $2, $3 );
148 sub sf { push @f, @_; }
149 $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf($1, $2)}ges;
150 diag "f:", join('|', @f), " left: |$line|";
151 $marc->add_fields( @f );
155 open(my $out, '>:utf8', "marc/$id");
156 print $out $marc->as_usmarc;
159 diag $marc->as_formatted;
161 return $marc->as_usmarc;
163 die "can't fetch COMARC format from ", $mech->content;