From a4271a1b8481c2c4b4ee8e76234da8a58fdaa57d Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 7 Nov 2005 19:03:07 +0000 Subject: [PATCH] helper script to rewrite bib-rec xml git-svn-id: svn://svn.open-ils.org/ILS/trunk@1976 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/import/update_marc.pl | 84 +++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 Open-ILS/src/extras/import/update_marc.pl diff --git a/Open-ILS/src/extras/import/update_marc.pl b/Open-ILS/src/extras/import/update_marc.pl new file mode 100755 index 0000000000..661f4df82d --- /dev/null +++ b/Open-ILS/src/extras/import/update_marc.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl -w +use strict; +use XML::LibXML; +use Time::HiRes qw/time/; +use Getopt::Long; +use Data::Dumper; +use Error qw/:try/; +use open qw/:utf8/; + +$|=1; + +my ($userid,$sourceid,$rec_id,$entry_file,$id_tag) = (1,2,1,'marc_update.sql','//*[@tag="035"][1]'); + +GetOptions ( + "sourceid" => \$sourceid, + "sql_output=s" => \$entry_file, + "userid=i" => \$userid, + "first=i" => \$rec_id, + "id_tag_xpath=s" => \$id_tag, +); + +my $tcn_map; + +open RE, ">$entry_file" or die "Can't open $entry_file! $!\n"; + +print RE <new; + +my $xml = ''; +while ( $xml .= ) { + chomp $xml; + next unless $xml; + + my $tcn = ''; + my $success = 0; + try { + my $doc = $parser->parse_string($xml);; + my @nodes = $doc->documentElement->findnodes( $id_tag ); + for my $n (@nodes) { + $tcn .= $n->textContent; + } + $tcn =~ s/^\s*(\.+)\s*/$1/o; + $tcn =~ s/\s+/_/go; + $success = 1; + } catch Error with { + my $e = shift; + warn $e; + warn $xml; + }; + next unless $success; + + $xml =~ s/\t/\\t/go; + $xml =~ s/'/''/go; + + $tcn =~ s/^.*?(\w+)\s*$/$1/go; + + unless ($tcn) { + warn "\nNo TCN found for rec # $rec_id\n"; + $xml = ''; + $rec_id++; + next; + } + + if (exists($$tcn_map{$tcn})) { + warn "\n !! TCN $tcn already exists!\n"; + $xml = ''; + next; + } + + print "."; + $$tcn_map{$tcn} = $rec_id; + + print RE "UPDATE biblio.record_entry SET marc = E'$xml' where id = $rec_id;\n"; + + $rec_id++; + $xml = ''; +} + + -- 2.43.2