6 use Time::HiRes qw/time/;
11 my $doc = XML::LibXML->new->parse_file($ARGV[0]);
75 print STDOUT join("\t", @base_elements);
76 foreach my $addr ( 1..3 ) {
77 print STDOUT "\t" . join("\t", @addr_elements);
79 print STDOUT "\tuserid_active\tinactive_barcode1\tinactive_barcode2";
82 for my $patron ( $doc->documentElement->childNodes ) {
83 next if ($patron->nodeType == 3);
85 my $bc = $patron->findvalue( 'user_id' ); $bc =~ s/^\s+//; $bc =~ s/\s+$//;
86 if (exists($s_map{$bc})) {
88 warn "\n!!! already saw barcode $bc, skipping\n";
94 unless (defined($bc)) {
95 my $xml = $patron->toString;
96 warn "\n!!! no barcode found in UMS data, user number $count, xml => $xml \n";
101 foreach my $e ( @base_elements ) {
102 my $v = $patron->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//;
103 if ( $v && ( $e eq 'birthdate' || $e eq 'user_priv_granted' || $e eq 'user_priv_expires' ) ) { $v = parse_date($v); }
104 print STDOUT ( $v ? $v : '' ) . "\t";
109 for my $addr ( $patron->findnodes( "Address" ) ) {
110 my $addr_type = $addr->getAttribute('addr_type');
111 $addresses{$addr_type} = $addr;
114 foreach my $t ( 1..3 ) {
115 if ($addresses{$t}) {
116 foreach my $e ( @addr_elements ) {
118 if ($e eq "known_bad") {
119 $v = $addresses{$t}->getAttribute( $e ); if ($v) { $v =~ s/^\s+//; $v =~ s/\s+$//; }
121 $v = $addresses{$t}->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//;
123 print STDOUT ( $v ? $v : '' ) . "\t";
126 foreach ( @addr_elements ) { print STDOUT "\t"; }
130 my $inactive_barcode1 = '';
131 my $inactive_barcode2 = '';
132 my $userid_active = 't';
133 my @barcodes = $patron->findnodes( "barcodes" );
134 for my $i_bc ( $barcodes[0]->findnodes( "barcode" ) ) {
135 my $active = $i_bc->getAttribute('active');
136 if ($active eq "0" && $i_bc->textContent eq $bc) {
137 $userid_active = 'f';
139 if ($active eq "0" && $i_bc->textContent ne $bc) {
140 if (! $inactive_barcode1 ) {
141 $inactive_barcode1 = $i_bc->textContent;
142 $inactive_barcode1 =~ s/^\s+//;
143 $inactive_barcode1 =~ s/\s+$//;
145 if (! $inactive_barcode2 ) {
146 $inactive_barcode2 = $i_bc->textContent;
147 $inactive_barcode2 =~ s/^\s+//;
148 $inactive_barcode2 =~ s/\s+$//;
150 warn "Extra barcode (" . $i_bc->textContent . ") for user with id = " . $bc . "\n";
155 print STDOUT "$userid_active\t$inactive_barcode1\t$inactive_barcode2";
167 if ($string eq 'NEVER') {
168 my (undef,undef,undef,$d,$m,$y) = localtime();
169 return sprintf('%04d-%02d-%02d', $y + 1920, $m + 1, $d);
170 } elsif (length($string) == 8 && $string =~ /^(\d{4})(\d{2})(\d{2})$/o) {
171 ($y,$m,$d) = ($1,$2,$3);
172 } elsif ($string =~ /(\d+)\D(\d+)\D(\d+)/o) { #looks like it's parsable
173 if ( length($3) > 2 ) { # looks like mm.dd.yyyy
174 if ( $1 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
175 if ($1 > 12 && $1 < 31 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
176 ($y,$m,$d) = ($3,$2,$1);
177 } elsif ($2 > 12 && $2 < 31 && $1 < 13) {
178 ($y,$m,$d) = ($3,$1,$2);
181 } elsif ( length($1) > 3 ) { # format probably yyyy.mm.dd
182 if ( $3 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
183 if ($2 > 12 && $2 < 32 && $3 < 13) { # well, actually it looks like yyyy.dd.mm -- why, I don't konw
184 ($y,$m,$d) = ($1,$3,$2);
185 } elsif ($3 > 12 && $3 < 31 && $2 < 13) {
186 ($y,$m,$d) = ($1,$2,$3);
189 } elsif ( $1 < 99 && $2 < 99 && $3 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
190 if ($3 < 7) { # probably 2000 or greater, 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) {
197 } else { # probably before 2000, mm.dd.yy
199 if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
201 } elsif ($2 > 12 && $2 < 32 && $1 < 13) {
209 if ($y && $m && $d) {
211 $date = sprintf('%04d-%02d-%-2d',$y, $m, $d)
212 if (new DateTime ( year => $y, month => $m, day => $d ));