Polaris patron extractor, first working version
[migration-tools.git] / polaris / extract_patrons
1 #!/usr/bin/perl -w
2
3 # Polaris exports patrons in MARC format.  This script turns the data into a TSV that can be imported with \copy.
4
5 use strict;
6 use MARC::Record; 
7 use MARC::File::USMARC; 
8 use Equinox::Migration::SubfieldMapper 1.004;
9
10 my $file = MARC::File::USMARC->in("PATRONS.mrc"); 
11 my $serial = 0;
12 my @modlist = qw( multi ignoremulti bib required ); # Not sure what these do, but I'll cargo-cult it for now
13 my $mapfile = 'patron.map';
14
15 # initialize map and taglist
16 my $sfmap = Equinox::Migration::SubfieldMapper->new( file => $mapfile, mods => \@modlist );
17
18 my $temp = $sfmap->tags(); # $temp is an arrayref
19 my @fields = sort @$temp;
20
21 while ( my $marc = $file->next() ) { 
22   # Preliminaries
23   print $serial++ . "\t";
24   print $marc->leader() . "\t";
25         print $marc->field('001')->data() . "\t";
26         print $marc->field('005')->data() . "\t";
27         print $marc->field('008')->data() . "\t";
28   # Fields and subfields beyond the preliminaries
29   foreach my $tag (@fields) {
30     my $temp = $sfmap->subfields($tag);
31     foreach my $sf (sort @$temp) {
32       if ($sfmap->has($tag, $sf)) {
33         print $marc->subfield($tag, $sf);
34       }
35       print "\t";
36     }    
37   }
38   print "\n"; 
39
40
41 $file->close(); 
42 undef $file;