spit out data from unicorn style holding tags from marc
authorJason Etheridge <jason@esilibrary.com>
Mon, 16 Jun 2008 05:54:02 +0000 (05:54 +0000)
committerJason Etheridge <jason@esilibrary.com>
Mon, 16 Jun 2008 05:54:02 +0000 (05:54 +0000)
spit_unicorn_marc_holdings.pl [new file with mode: 0755]

diff --git a/spit_unicorn_marc_holdings.pl b/spit_unicorn_marc_holdings.pl
new file mode 100755 (executable)
index 0000000..93b385a
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+use MARC::Batch;
+use MARC::File::XML ( BinaryEncoding => 'utf-8' );
+use MARC::Field;
+use Unicode::Normalize;
+
+my $count = 0;
+
+binmode(STDOUT, ':utf8');
+binmode(STDIN, ':utf8');
+
+print join("\t",
+    "bib id",
+    "library",
+    "barcode",
+    "current location",
+    "home location",
+    "call number",
+    "item type",
+    "acq date",
+    "price",
+    "circulate flag",
+    "total charges",
+    "cat1",
+    "cat2"
+) . "\n";
+
+foreach my $argnum ( 0 .. $#ARGV ) {
+
+       print STDERR "Processing " . $ARGV[$argnum] . "\n";
+
+       my $batch = MARC::Batch->new('XML',$ARGV[$argnum]);
+       $batch->strict_off();
+       $batch->warnings_off();
+
+       while ( my $record = $batch->next() ) {
+
+        $count++;
+
+               print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
+        my $my_903a = $record->field('903')->subfield('a'); # target bib id's here
+        my @tags = $record->field('999');
+        foreach my $tag ( @tags ) {
+            print join("\t",
+                $my_903a,
+                $tag->subfield('m'), # library
+                $tag->subfield('i'), # barcode
+                $tag->subfield('k'), # current location
+                $tag->subfield('l'), # home location
+                $tag->subfield('a'), # call number
+                $tag->subfield('t'), # item type
+                $tag->subfield('u'), # acq date
+                $tag->subfield('p'), # price
+                $tag->subfield('r'), # circulate flag
+                $tag->subfield('n'), # total charges
+                $tag->subfield('x'), # cat1
+                $tag->subfield('z')  # cat2
+            ) . "\n";
+        }
+
+       }
+       print STDERR "Processed $count records\n";
+}