From: miker Date: Wed, 24 Jan 2007 03:08:40 +0000 (+0000) Subject: adding MARC export script X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6d90ef31096fd72098a3d6932bd6fe286e9f3453;p=Evergreen.git adding MARC export script git-svn-id: svn://svn.open-ils.org/ILS/trunk@6810 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/support-scripts/marc_export b/Open-ILS/src/support-scripts/marc_export new file mode 100755 index 0000000000..e7dda64737 --- /dev/null +++ b/Open-ILS/src/support-scripts/marc_export @@ -0,0 +1,87 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use OpenSRF::System; +use OpenSRF::EX qw/:try/; +use OpenSRF::AppSession; +use OpenSRF::Utils::SettingsClient; +use OpenILS::Application::AppUtils; +use OpenILS::Utils::Fieldmapper; + +use MARC::Record; +use MARC::File::XML; +use UNIVERSAL::require; + +use Getopt::Long; + +my @formats = qw/USMARC UNIMARC XML/; + +my ($config,$format,$encoding,$help) = ('/openils/conf/bootstrap.conf','USMARC','MARC8'); + +GetOptions( + 'help' => \$help, + 'config=s' => \$config, + 'format=s' => \$format, + 'encoding=s' => \$encoding, +); + +if ($help) { + print <<" HELP"; +Usage: $0 [options] + --help or -h This screen. + --config or -c Configuration file [/openils/conf/bootstrap.conf] + --format or -f Output format (USMARC, UNIMARC, XML) [USMARC] + --encoding or -e Output Encoding (UTF-8, ISO-8859-?, MARC8) [MARC8] + +Example: + + cat list_of_ids | $0 > output_file + + HELP + exit; +} + +$format = uc($format); +$encoding = uc($encoding); + +binmode(STDOUT, ':raw') if ($encoding ne 'UTF-8'); +binmode(STDOUT, ':utf8') if ($encoding eq 'UTF-8'); + +if (!grep { $format eq $_ } @formats) { + die "Please select a supported format. ". + "Right now that means one of [". + join('|',@formats). "]\n"; +} + +if ($format ne 'XML') { + my $type = 'MARC::File::' . $format; + $type->require; +} + +OpenSRF::System->bootstrap_client( config_file => $config ); +Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); + +my $ses = OpenSRF::AppSession->connect('open-ils.cstore'); + +print <
+ +HEADER + +while ( my $i = <> ) { + my $bib = $ses->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve', $i )->gather(1); + + next unless $bib; + + if ($format eq 'XML') { + print $bib->marc . "\n"; + } else { + print MARC::Record->new_from_xml( $bib->marc, $encoding, $format )->as_usmarc; + } +} + +print "\n" if ($format eq 'XML'); + +$ses->disconnect; +