adding compact score
[migration-tools.git] / split_colfax_marc_holdings.pl
1 #!/usr/bin/perl
2 use open ':utf8';
3 use Error qw/:try/;
4 use MARC::Batch;
5 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
6 use MARC::Field;
7 use Unicode::Normalize;
8
9 my $count = 0;
10
11 binmode(STDOUT, ':utf8');
12 binmode(STDIN, ':utf8');
13
14 print join("\t",
15     "bib id",
16     "library",
17     "barcode",
18     "current location",
19     "home location",
20     "call number",
21     "item type",
22     "acq date",
23     "price",
24     "circulate flag",
25     "total charges",
26     "cat1",
27     "cat2"
28 ) . "\n";
29
30 foreach my $argnum ( 0 .. $#ARGV ) {
31
32         print STDERR "Processing " . $ARGV[$argnum] . "\n";
33
34     my $M;
35     open $M, '<:utf8', $ARGV[$argnum];
36     my $batch = MARC::Batch->new('XML',$M);
37
38         $batch->strict_off();
39         $batch->warnings_off();
40
41         my $record = -1;
42         while ( try { $record = $batch->next() } otherwise { $record = -1 } ) {
43                 next if ($record == -1);
44
45         $count++;
46
47                 print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
48         my $my_903a = $record->field('903')->subfield('a'); # target bib id's here
49         my @tags = $record->field('852');
50         foreach my $tag ( @tags ) {
51                 my $lib = $tag->subfield(''); # library
52                 my $barcode = $tag->subfield('p'); # barcod
53                 my $loc = $tag->subfield(''); # current location
54                 my $home_loc = $tag->subfield('c'); # home location
55                 my $cn = $tag->subfield('h'); # call number
56                 my $type = $tag->subfield(''); # item type
57                 my $create_date = $tag->subfield(''); # acq date
58                 my $price = $tag->subfield('9'); # price
59                 $price =~ s/[^0-9\.]//g;
60                 my $circ_flag = $tag->subfield(''); # circulate flag
61                 my $total_circ = $tag->subfield(''); # total charges
62                 my $cat1 = $tag->subfield(''); # cat1
63                 my $cat2 = $tag->subfield(''); # cat2
64             print join("\t",
65                 $my_903a, $lib, $barcode, $loc, $home_loc,
66                 $cn, $type, $create_date, $price, $circ_flag,
67                 $total_circ, $cat1, $cat2) . "\n";
68         }
69
70         }
71         print STDERR "Processed $count records\n";
72 }