From c16c4d4c903563ce83f4c6df5d6c51a4c6742b2c Mon Sep 17 00:00:00 2001 From: Rogan Hamby Date: Tue, 14 Jul 2020 12:56:29 -0400 Subject: [PATCH] enhancements to mig prepbibs --- emig.d/bin/mig-prepbibs | 20 ++++++++++++++++---- kmig.d/bin/mig-prepbibs | 19 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/emig.d/bin/mig-prepbibs b/emig.d/bin/mig-prepbibs index 69c2674..93d1c66 100755 --- a/emig.d/bin/mig-prepbibs +++ b/emig.d/bin/mig-prepbibs @@ -45,19 +45,31 @@ pod2usage(-verbose => 2) if defined $ARGV[0] && $ARGV[0] eq '--help'; pod2usage(-verbose => 1) if ! $ARGV[1]; my $infile; +my $i = 0; my $ret = GetOptions( 'file:s' => \$infile ); my $outfile = $infile . '.prepped_xml'; +my $errorfile = $infile . '.errors_xml'; open my $outfh, '>:utf8', $outfile or die "Can't open output file $!\n"; - -my $batch = MARC::Batch->new( 'USMARC', $infile ); +open my $errorfh, '>:utf8', $errorfile or die "Can't open error file $!\n"; + +my $filetype = `file $infile`; +my $batch; +if ($filetype =~ m/MARC21/) { + $batch = MARC::Batch->new( 'USMARC', $infile ); +} else { + $batch = MARC::Batch->new( 'XML', $infile ); +} $batch->strict_off(); -while ( my $record = $batch->next() ) { +my $record; +while ( eval {$record = $batch->next()} or do { if ($@) { print $errorfh $record->as_xml(); next; } } ) { + $i++; + print "Processed: $i\n" if ($i % 100) == 0; my @nnn = $record->field('852'); foreach my $n (@nnn) { $n->set_tag('851'); @@ -68,7 +80,7 @@ while ( my $record = $batch->next() ) { close ($infile); close ($outfile); - +close ($errorfile); ########### functions diff --git a/kmig.d/bin/mig-prepbibs b/kmig.d/bin/mig-prepbibs index b3a89f1..7c86c38 100755 --- a/kmig.d/bin/mig-prepbibs +++ b/kmig.d/bin/mig-prepbibs @@ -45,19 +45,30 @@ pod2usage(-verbose => 2) if defined $ARGV[0] && $ARGV[0] eq '--help'; pod2usage(-verbose => 1) if ! $ARGV[1]; my $infile; +my $i = 0; my $ret = GetOptions( 'file:s' => \$infile ); my $outfile = $infile . '.prepped_xml'; +my $errorfile = $infile . '.errors_xml'; open my $outfh, '>:utf8', $outfile or die "Can't open output file $!\n"; - -my $batch = MARC::Batch->new( 'USMARC', $infile ); +open my $errorfh, '>:utf8', $errorfile or die "Can't open error file $!\n"; + +my $filetype = `file $infile`; +my $batch; +if ($filetype =~ m/MARC21/) { + $batch = MARC::Batch->new( 'USMARC', $infile ); +} else { + $batch = MARC::Batch->new( 'XML', $infile ); +} $batch->strict_off(); -while ( my $record = $batch->next() ) { +while ( eval {$record = $batch->next()} or do { if ($@) { print $errorfh $record->as_xml(); next; } } ) { + $i++; + print "Processed: $i\n" if ($i % 100) == 0; my @nnn = $record->field('999'); foreach my $n (@nnn) { $n->set_tag('998'); @@ -68,7 +79,7 @@ while ( my $record = $batch->next() ) { close ($infile); close ($outfile); - +close ($errorfile); ########### functions -- 1.7.2.5