6 use Time::HiRes qw/time/;
11 my $doc = XML::LibXML->new->parse_file($ARGV[0]);
68 print STDOUT join("\t", @base_elements);
69 foreach my $addr ( 1..3 ) {
70 print STDOUT "\t" . join("\t", @addr_elements);
72 print STDOUT "\tuserid_active\tinactive_barcode1\tinactive_barcode2";
75 for my $patron ( $doc->documentElement->childNodes ) {
76 next if ($patron->nodeType == 3);
78 my $bc = $patron->findvalue( 'user_id' ); $bc =~ s/^\s+//; $bc =~ s/\s+$//;
79 if (exists($s_map{$bc})) {
81 warn "\n!!! already saw barcode $bc, skipping\n";
87 unless (defined($bc)) {
88 my $xml = $patron->toString;
89 warn "\n!!! no barcode found in UMS data, user number $count, xml => $xml \n";
94 foreach my $e ( @base_elements ) {
95 my $v = $patron->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//;
96 if ( $v && ( $e eq 'birthdate' || $e eq 'user_priv_granted' || $e eq 'user_priv_expires' ) ) { $v = parse_date($v); }
97 print STDOUT ( $v ? $v : '' ) . "\t";
102 for my $addr ( $patron->findnodes( "Address" ) ) {
103 my $addr_type = $addr->getAttribute('addr_type');
104 $addresses{$addr_type} = $addr;
107 foreach my $t ( 1..3 ) {
108 if ($addresses{$t}) {
109 foreach my $e ( @addr_elements ) {
111 if ($e eq "known_bad") {
112 $v = $addresses{$t}->getAttribute( $e ); if ($v) { $v =~ s/^\s+//; $v =~ s/\s+$//; }
114 $v = $addresses{$t}->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//;
116 print STDOUT ( $v ? $v : '' ) . "\t";
119 foreach ( @addr_elements ) { print STDOUT "\t"; }
123 my $inactive_barcode1 = '';
124 my $inactive_barcode2 = '';
125 my $userid_active = 't';
126 my @barcodes = $patron->findnodes( "barcodes" );
127 for my $i_bc ( $barcodes[0]->findnodes( "barcode" ) ) {
128 my $active = $i_bc->getAttribute('active');
129 if ($active eq "0" && $i_bc->textContent eq $bc) {
130 $userid_active = 'f';
132 if ($active eq "0" && $i_bc->textContent ne $bc) {
133 if (! $inactive_barcode1 ) {
134 $inactive_barcode1 = $i_bc->textContent;
135 $inactive_barcode1 =~ s/^\s+//;
136 $inactive_barcode1 =~ s/\s+$//;
138 if (! $inactive_barcode2 ) {
139 $inactive_barcode2 = $i_bc->textContent;
140 $inactive_barcode2 =~ s/^\s+//;
141 $inactive_barcode2 =~ s/\s+$//;
143 warn "Extra barcode (" . $i_bc->textContent . ") for user with id = " . $bc . "\n";
148 print STDOUT "$userid_active\t$inactive_barcode1\t$inactive_barcode2";
160 if ($string eq 'NEVER') {
161 my (undef,undef,undef,$d,$m,$y) = localtime();
162 return sprintf('%04d-%02d-%02d', $y + 1920, $m + 1, $d);
163 } elsif (length($string) == 8 && $string =~ /^(\d{4})(\d{2})(\d{2})$/o) {
164 ($y,$m,$d) = ($1,$2,$3);
165 } elsif ($string =~ /(\d+)\D(\d+)\D(\d+)/o) { #looks like it's parsable
166 if ( length($3) > 2 ) { # looks like mm.dd.yyyy
167 if ( $1 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
168 if ($1 > 12 && $1 < 31 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
169 ($y,$m,$d) = ($3,$2,$1);
170 } elsif ($2 > 12 && $2 < 31 && $1 < 13) {
171 ($y,$m,$d) = ($3,$1,$2);
174 } elsif ( length($1) > 3 ) { # format probably yyyy.mm.dd
175 if ( $3 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
176 if ($2 > 12 && $2 < 32 && $3 < 13) { # well, actually it looks like yyyy.dd.mm -- why, I don't konw
177 ($y,$m,$d) = ($1,$3,$2);
178 } elsif ($3 > 12 && $3 < 31 && $2 < 13) {
179 ($y,$m,$d) = ($1,$2,$3);
182 } elsif ( $1 < 99 && $2 < 99 && $3 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
183 if ($3 < 7) { # probably 2000 or greater, mm.dd.yy
185 if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
187 } elsif ($2 > 12 && $2 < 32 && $1 < 13) {
190 } else { # probably before 2000, mm.dd.yy
192 if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
194 } elsif ($2 > 12 && $2 < 32 && $1 < 13) {
202 if ($y && $m && $d) {
204 $date = sprintf('%04d-%02d-%-2d',$y, $m, $d)
205 if (new DateTime ( year => $y, month => $m, day => $d ));