preserve dates we can't parse; we'll punt to postgres
[migration-tools.git] / spit_unicorn_marc_holdings.pl
1 #!/usr/bin/perl
2 use MARC::Batch;
3 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
4 use MARC::Field;
5 use Unicode::Normalize;
6
7 my $count = 0;
8
9 binmode(STDOUT, ':utf8');
10 binmode(STDIN, ':utf8');
11
12 print join("\t",
13     "bib id",
14     "library",
15     "barcode",
16     "current location",
17     "home location",
18     "call number",
19     "item type",
20     "acq date",
21     "price",
22     "circulate flag",
23     "total charges",
24     "cat1",
25     "cat2"
26 ) . "\n";
27
28 foreach my $argnum ( 0 .. $#ARGV ) {
29
30         print STDERR "Processing " . $ARGV[$argnum] . "\n";
31
32         my $batch = MARC::Batch->new('XML',$ARGV[$argnum]);
33         $batch->strict_off();
34         $batch->warnings_off();
35
36         while ( my $record = $batch->next() ) {
37
38         $count++;
39
40                 print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
41         my $my_903a = $record->field('903')->subfield('a'); # target bib id's here
42         my @tags = $record->field('999');
43         foreach my $tag ( @tags ) {
44             print join("\t",
45                 $my_903a,
46                 $tag->subfield('m') || '', # library
47                 $tag->subfield('i') || '', # barcode
48                 $tag->subfield('k') || '', # current location
49                 $tag->subfield('l') || '', # home location
50                 $tag->subfield('a') || '', # call number
51                 $tag->subfield('t') || '', # item type
52                 $tag->subfield('u') || '', # acq date
53                 $tag->subfield('p') || '', # price
54                 $tag->subfield('r') || '', # circulate flag
55                 $tag->subfield('n') || '', # total charges
56                 $tag->subfield('x') || '', # cat1
57                 $tag->subfield('z') || ''  # cat2
58             ) . "\n";
59         }
60
61         }
62         print STDERR "Processed $count records\n";
63 }