generate darhiv marc based on agerestriction
authordpavlin <dpavlin@rot13.org>
Tue, 26 May 2015 17:33:17 +0000 (19:33 +0200)
committerdpavlin <dpavlin@rot13.org>
Tue, 26 May 2015 17:33:17 +0000 (19:33 +0200)
tsv2eprints.pl

index dec518b..4b225bd 100755 (executable)
@@ -22,6 +22,8 @@ use LWP::Simple;
 
 use EPrints;
 
+my $stat;
+
 my $ep = EPrints->new();
 my $repo = $ep->repository( 'snz' );
 #$repo->{config}->{enable_file_imports} = 1;
@@ -43,6 +45,7 @@ $list->map( sub {
 
        $info->{biblionumber}->{$biblionumber}++;
        $info->{count}++;
+       $stat->{snz}++;
 
 }, $info );
 warn dump( $info );
@@ -91,15 +94,25 @@ warn "# got ", scalar keys %$files, " files\n";
 
 store $files, "$koha_path.biblionumber.file";
 
-my $stat;
-
 open(my $tsv_fh,  '<:encoding(UTF-8)', "$koha_path.tsv");
 open(my $marc_fh, '<', "$koha_path.marc");
 open(my $import_fh, '>', "$koha_path.import.marc");
+open(my $darhiv_fh, '>', "$koha_path.darhiv.marc");
 
-my $last_offset = 0;
+our $offset;
+our $biblionumber;
 my @cols;
 
+sub output_marc {
+       my $output_fh = shift;
+       seek $marc_fh, $offset, 0;
+       read $marc_fh, my $marc_len, 5;
+       seek $marc_fh, $offset, 0;
+
+       read $marc_fh, my $marc, $marc_len;
+       print $output_fh $marc;
+}
+
 while(<$tsv_fh>) {
        chomp;
        my $line = $_;
@@ -113,10 +126,11 @@ while(<$tsv_fh>) {
        my @v = split(/\t/, $line, $#cols + 1);
        my %row;
        @row{@cols} = @v;
-#warn "## row = ",dump( \%row );
+       warn "## row = ",dump( \%row );
+       $stat->{tsv_rows}++;
 
-       my $offset = $row{offset} // die "no offset";
-       my $biblionumber = $row{biblionumber} || die "no biblionumber";
+       $offset = $row{offset} // die "no offset";
+       $biblionumber = $row{biblionumber} || die "no biblionumber";
 
 #      warn "# ", join(' ', map { $row{$_} } qw(biblionumber title)), "\n";
 
@@ -130,17 +144,18 @@ while(<$tsv_fh>) {
 
                        $stat->{new}++;
 
-                       seek $marc_fh, $offset, 0;
-                       read $marc_fh, my $marc_len, 5;
-                       seek $marc_fh, $offset, 0;
-
-                       read $marc_fh, my $marc, $marc_len;
-                       print $import_fh $marc;
+                       output_marc $import_fh;
                        warn "# NEW ", join(' ', map { $row{$_} } qw(biblionumber title)), "\n";
 #                      warn "# NEW $biblionumber\n";
 
                }
 
+               # darhiv export to marc
+               if ( $row{agerestriction} > 0 ) {
+                       output_marc $darhiv_fh;
+                       $stat->{darhiv}++;
+               }
+
        } else {
                $stat->{missing}++;
        }