6 use Time::HiRes qw/time/;
11 my $doc = XML::LibXML->new->parse_file($ARGV[0]);
70 print STDOUT join("\t", @base_elements);
71 foreach my $addr ( 1..3 ) {
72 print STDOUT "\t" . join("\t", @addr_elements);
74 print STDOUT "\tuserid_active\tinactive_barcode1\tinactive_barcode2";
77 for my $patron ( $doc->documentElement->childNodes ) {
78 next if ($patron->nodeType == 3);
80 my $bc = $patron->findvalue( 'user_id' ); $bc =~ s/^\s+//; $bc =~ s/\s+$//;
81 if (exists($s_map{$bc})) {
83 warn "\n!!! already saw barcode $bc, skipping\n";
89 unless (defined($bc)) {
90 my $xml = $patron->toString;
91 warn "\n!!! no barcode found in UMS data, user number $count, xml => $xml \n";
96 foreach my $e ( @base_elements ) {
97 my $v = $patron->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//;
98 if ( $v && ( $e eq 'birthdate' || $e eq 'user_priv_granted' || $e eq 'user_priv_expires' ) ) { $v = parse_date($v); }
99 print STDOUT ( $v ? $v : '' ) . "\t";
104 for my $addr ( $patron->findnodes( "Address" ) ) {
105 my $addr_type = $addr->getAttribute('addr_type');
106 $addresses{$addr_type} = $addr;
109 foreach my $t ( 1..3 ) {
110 if ($addresses{$t}) {
111 foreach my $e ( @addr_elements ) {
113 if ($e eq "known_bad") {
114 $v = $addresses{$t}->getAttribute( $e ); if ($v) { $v =~ s/^\s+//; $v =~ s/\s+$//; }
116 $v = $addresses{$t}->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//;
118 print STDOUT ( $v ? $v : '' ) . "\t";
121 foreach ( @addr_elements ) { print STDOUT "\t"; }
125 my $inactive_barcode1 = '';
126 my $inactive_barcode2 = '';
127 my $userid_active = 't';
128 my @barcodes = $patron->findnodes( "barcodes" );
129 for my $i_bc ( $barcodes[0]->findnodes( "barcode" ) ) {
130 my $active = $i_bc->getAttribute('active');
131 if ($active eq "0" && $i_bc->textContent eq $bc) {
132 $userid_active = 'f';
134 if ($active eq "0" && $i_bc->textContent ne $bc) {
135 if (! $inactive_barcode1 ) {
136 $inactive_barcode1 = $i_bc->textContent;
137 $inactive_barcode1 =~ s/^\s+//;
138 $inactive_barcode1 =~ s/\s+$//;
140 if (! $inactive_barcode2 ) {
141 $inactive_barcode2 = $i_bc->textContent;
142 $inactive_barcode2 =~ s/^\s+//;
143 $inactive_barcode2 =~ s/\s+$//;
145 warn "Extra barcode (" . $i_bc->textContent . ") for user with id = " . $bc . "\n";
150 print STDOUT "$userid_active\t$inactive_barcode1\t$inactive_barcode2";
162 if ($string eq 'NEVER') {
163 my (undef,undef,undef,$d,$m,$y) = localtime();
164 return sprintf('%04d-%02d-%02d', $y + 1920, $m + 1, $d);
165 } elsif (length($string) == 8 && $string =~ /^(\d{4})(\d{2})(\d{2})$/o) {
166 ($y,$m,$d) = ($1,$2,$3);
167 } elsif ($string =~ /(\d+)\D(\d+)\D(\d+)/o) { #looks like it's parsable
168 if ( length($3) > 2 ) { # looks like mm.dd.yyyy
169 if ( $1 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
170 if ($1 > 12 && $1 < 31 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
171 ($y,$m,$d) = ($3,$2,$1);
172 } elsif ($2 > 12 && $2 < 31 && $1 < 13) {
173 ($y,$m,$d) = ($3,$1,$2);
176 } elsif ( length($1) > 3 ) { # format probably yyyy.mm.dd
177 if ( $3 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
178 if ($2 > 12 && $2 < 32 && $3 < 13) { # well, actually it looks like yyyy.dd.mm -- why, I don't konw
179 ($y,$m,$d) = ($1,$3,$2);
180 } elsif ($3 > 12 && $3 < 31 && $2 < 13) {
181 ($y,$m,$d) = ($1,$2,$3);
184 } elsif ( $1 < 99 && $2 < 99 && $3 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
185 if ($3 < 7) { # probably 2000 or greater, mm.dd.yy
187 if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
189 } elsif ($2 > 12 && $2 < 32 && $1 < 13) {
192 } else { # probably before 2000, mm.dd.yy
194 if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
196 } elsif ($2 > 12 && $2 < 32 && $1 < 13) {
204 if ($y && $m && $d) {
206 $date = sprintf('%04d-%02d-%-2d',$y, $m, $d)
207 if (new DateTime ( year => $y, month => $m, day => $d ));