track failed (evel fail) records
[migration-tools.git] / fingerprinter
index 46759b9..feb6c19 100755 (executable)
@@ -6,9 +6,11 @@ use open ':utf8';
 use Getopt::Long;
 use MARC::Batch;
 use Unicode::Normalize;
+use MARC::File::XML ( BinaryEncoding => 'utf-8' );
 
 my $conf  = {}; # configuration hashref
 my $count = 0;
+my $failcount = 0;
 my $start = time;
 $| = 1;
 
@@ -29,8 +31,10 @@ for my $file (@ARGV) {
     $batch->warnings_off();
 
     while ( eval { $record = $batch->next } ) {
-        my $marc = undef;
+        if ($@)
+          { print XF "MARC::Batch error $@"; $failcount++; next }
         $count++; progress_ticker();
+        my $marc = undef;
         unless ( defined $record )
           { dump_exception($marc); next; }
 
@@ -48,8 +52,12 @@ for my $file (@ARGV) {
         dump_fingerprints($marc);
     }
 }
-print "\nProcessed $count records\n" unless $conf->{quiet};
 
+unless ($conf->{quiet}) {
+    print "\nSuccessfully processed:\t$count\n";
+    print "Failed to process:\t$failcount\n";
+    print "Total: ", ($count + $failcount), "\n";
+}
 
 
 =head2 populate_marc
@@ -301,15 +309,15 @@ sub initialize {
 
     # set defaults if told to do so
     if ($c->{incoming}) {
-        $c->{tag} = 903;
-        $c->{subfield} = 'a';
-        $c->{output} = 'incoming.fp';
-        $c->{exception} = 'incoming.ex';
+        $c->{tag} = 903 unless defined $c->{tag};
+        $c->{subfield} = 'a' unless defined $c->{subfield};
+        $c->{output} = 'incoming.fp' unless defined $c->{output};
+        $c->{exception} = 'incoming.ex' unless defined $c->{exception};
     } elsif ($c->{incumbent}) {
-        $c->{tag} = 901;
-        $c->{subfield} = 'c';
-        $c->{output} = 'incumbent.fp';
-        $c->{exception} = 'incumbent.ex';
+        $c->{tag} = 901 unless defined $c->{tag};
+        $c->{subfield} = 'c' unless defined $c->{subfield};
+        $c->{output} = 'incumbent.fp' unless defined $c->{output};
+        $c->{exception} = 'incumbent.ex' unless defined $c->{exception};
     }
 
     my @keys = keys %{$c};
@@ -352,8 +360,8 @@ Options
   --incoming     Set -r to 'full'; -t, -s, -o, -x to incoming defaults
   --incumbent    Set -r to 'full'; -t, -s, -o, -x to incumbent defaults
 
-                 Example: '$0 --incoming' is equivalent to
-                          '$0 -r full -t 903 -s a -o incoming.fp -x incoming.ex'
+  Example: '$0 --incoming' is equivalent to
+           '$0 -r full -t 903 -s a -o incoming.fp -x incoming.ex'
 
   --quiet    -q  Don't write status messages to STDOUT
 HELP