cleanup code a bit
authordpavlin <dpavlin@rot13.org>
Tue, 26 May 2015 11:54:04 +0000 (13:54 +0200)
committerdpavlin <dpavlin@rot13.org>
Tue, 26 May 2015 11:54:50 +0000 (13:54 +0200)
tsv2eprints.pl

index a275fa4..7c9ea89 100755 (executable)
@@ -64,8 +64,6 @@ $repo->terminate();
 
 =cut
 
-our $eprintid = 1;
-
 my $files;
 
 my $mkp_path = "/mnt/share/MKP/ELEKTRONIÄŒKI DOKUMENTI/EL.DOKUMENTI PO BIBLIOBROJU/";
@@ -103,6 +101,7 @@ my $last_offset = 0;
 my @cols;
 
 while(<$tsv_fh>) {
+       chomp;
        my $line = $_;
        $line =~ s/[\n\r]+$//;
 
@@ -111,7 +110,7 @@ while(<$tsv_fh>) {
                next;
        }
 
-       my @v = split(/\t/, $_, $#cols + 1);
+       my @v = split(/\t/, $line, $#cols + 1);
        my %row;
        @row{@cols} = @v;
 #warn "## row = ",dump( \%row );
@@ -119,9 +118,7 @@ while(<$tsv_fh>) {
        my $offset = $row{offset} // die "no offset";
        my $biblionumber = $row{biblionumber} || die "no biblionumber";
 
-       warn "# ", join(' ', map { $row{$_} } qw(offset biblionumber title)), "\n";
-
-       exit if $ENV{LAST} && $eprintid >= $ENV{LAST};
+#      warn "# ", join(' ', map { $row{$_} } qw(biblionumber title)), "\n";
 
        if ( delete $files->{$biblionumber} ) {
                $stat->{file}++;
@@ -136,7 +133,9 @@ while(<$tsv_fh>) {
                        seek $marc_fh, $last_offset, 0;
                        read $marc_fh, my $marc, $offset - $last_offset;
                        print $import_fh $marc;
-                       warn "# marc $biblionumber\n";
+                       warn "# NEW ", join(' ', map { $row{$_} } qw(biblionumber title)), "\n";
+#                      warn "# NEW $biblionumber\n";
+
                }
 
        } else {
@@ -160,6 +159,7 @@ foreach my $biblionumber ( keys %$files ) {
        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!";
+               $stat->{koha}++;
        } else {
                warn "ERROR: can't fetch $biblionumber from koha";
        }