Polaris patron extractor, first working version
authorBen Ostrowsky <ben@esilibrary.com>
Tue, 5 Jan 2010 14:30:27 +0000 (14:30 +0000)
committerBen Ostrowsky <ben@esilibrary.com>
Tue, 5 Jan 2010 14:30:27 +0000 (14:30 +0000)
polaris/extract_patrons [new file with mode: 0755]

diff --git a/polaris/extract_patrons b/polaris/extract_patrons
new file mode 100755 (executable)
index 0000000..840028d
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/perl -w
+
+# Polaris exports patrons in MARC format.  This script turns the data into a TSV that can be imported with \copy.
+
+use strict;
+use MARC::Record; 
+use MARC::File::USMARC; 
+use Equinox::Migration::SubfieldMapper 1.004;
+
+my $file = MARC::File::USMARC->in("PATRONS.mrc"); 
+my $serial = 0;
+my @modlist = qw( multi ignoremulti bib required ); # Not sure what these do, but I'll cargo-cult it for now
+my $mapfile = 'patron.map';
+
+# initialize map and taglist
+my $sfmap = Equinox::Migration::SubfieldMapper->new( file => $mapfile, mods => \@modlist );
+
+my $temp = $sfmap->tags(); # $temp is an arrayref
+my @fields = sort @$temp;
+
+while ( my $marc = $file->next() ) { 
+  # Preliminaries
+  print $serial++ . "\t";
+  print $marc->leader() . "\t";
+       print $marc->field('001')->data() . "\t";
+       print $marc->field('005')->data() . "\t";
+       print $marc->field('008')->data() . "\t";
+  # Fields and subfields beyond the preliminaries
+  foreach my $tag (@fields) {
+    my $temp = $sfmap->subfields($tag);
+    foreach my $sf (sort @$temp) {
+      if ($sfmap->has($tag, $sf)) {
+        print $marc->subfield($tag, $sf);
+      }
+      print "\t";
+    }    
+  }
+  print "\n"; 
+} 
+
+$file->close(); 
+undef $file;