X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=tsv2eprints.pl;fp=tsv2eprints.pl;h=a275fa47c4bf6d0c8afa3f5bb86daa42a716d529;hb=b047d950bd02f8812aaeec160bfd342f4ac015cd;hp=254f51d03f5f4914e9966ddb4aa461c4a7b89e23;hpb=8bb93b62c29f5e7c028c63971d7ff690692e4a6d;p=koha-eprints diff --git a/tsv2eprints.pl b/tsv2eprints.pl index 254f51d..a275fa4 100755 --- a/tsv2eprints.pl +++ b/tsv2eprints.pl @@ -20,23 +20,37 @@ use Data::Dump qw(dump); use Storable; use LWP::Simple; -=for eprints-api - use EPrints; -my $institution = 'Grafički fakultet'; my $ep = EPrints->new(); -my $repo = $ep->repository( 'grf' ); -$repo->{config}->{enable_file_imports} = 1; -$repo->{config}->{enable_web_imports} = 1; - +my $repo = $ep->repository( 'snz' ); +#$repo->{config}->{enable_file_imports} = 1; +#$repo->{config}->{enable_web_imports} = 1; my $dataset = $repo->dataset( 'eprint' ); my $list = $dataset->search; my $count = $list->count; warn "# found [$count] eprints\n"; -my $eprint = $dataset->dataobj( 21 ); -warn dump( $eprint->get_value('institution'), $institution ); +warn ref( $list ); + +#warn "# ids = ",dump( $list->ids ); + +my $info = { count => 0 }; +$list->map( sub { + my( $session, $dataset, $eprint, $info ) = @_; + + my $biblionumber = $eprint->get_value('biblionumber'); + + $info->{biblionumber}->{$biblionumber}++; + $info->{count}++; + +}, $info ); +warn dump( $info ); + +=for update + +#my $eprint = $dataset->dataobj( 21 ); +#warn dump( $eprint->get_value('institution'), $institution ); warn dump( $eprint ); @@ -100,7 +114,7 @@ while(<$tsv_fh>) { my @v = split(/\t/, $_, $#cols + 1); my %row; @row{@cols} = @v; -warn "## row = ",dump( \%row ); +#warn "## row = ",dump( \%row ); my $offset = $row{offset} // die "no offset"; my $biblionumber = $row{biblionumber} || die "no biblionumber"; @@ -112,10 +126,18 @@ warn "## row = ",dump( \%row ); if ( delete $files->{$biblionumber} ) { $stat->{file}++; - seek $marc_fh, $last_offset, 0; - read $marc_fh, my $marc, $offset - $last_offset; - print $import_fh $marc; - warn "# marc $biblionumber\n"; + if ( $info->{biblionumber}->{$biblionumber} ) { + $stat->{existing}++; + warn "EXISTING $biblionumber found in eprints\n"; + } else { + + $stat->{new}++; + + seek $marc_fh, $last_offset, 0; + read $marc_fh, my $marc, $offset - $last_offset; + print $import_fh $marc; + warn "# marc $biblionumber\n"; + } } else { $stat->{missing}++; @@ -128,6 +150,13 @@ warn "## row = ",dump( \%row ); warn "# files left ", dump($files); foreach my $biblionumber ( keys %$files ) { + + if ( $info->{biblionumber}->{$biblionumber} ) { + $stat->{existing}++; + warn "EXISTING $biblionumber found in eprints\n"; + next; + } + if ( my $marc = get("https://koha.ffzg.hr/cgi-bin/koha/opac-export.pl?op=export&bib=$biblionumber&format=utf8") ) { print $import_fh $marc; warn "## marc $biblionumber from koha!";