6 use Time::HiRes qw/time/;
11 my $doc = XML::LibXML->new->parse_file($ARGV[0]);
61 print STDOUT join("\t", @base_elements);
62 foreach my $addr ( 1..3 ) {
63 print STDOUT "\t" . join("\t", @addr_elements);
65 print STDOUT "\tinactive_barcode1\tinactive_barcode2";
68 for my $patron ( $doc->documentElement->childNodes ) {
69 next if ($patron->nodeType == 3);
71 my $bc = $patron->findvalue( 'user_id' );
72 if (exists($s_map{$bc})) {
74 warn "\n!!! already saw barcode $bc, skipping\n";
80 unless (defined($bc)) {
81 my $xml = $patron->toString;
82 warn "\n!!! no barcode found in UMS data, user number $count, xml => $xml \n";
87 foreach my $e ( @base_elements ) {
88 my $v = $patron->findvalue( $e );
89 if ( $v && ( $e eq 'birthdate' || $e eq 'user_priv_granted' || $e eq 'user_priv_expires' ) ) { $v = parse_date($v); }
90 print STDOUT ( $v ? $v : '' ) . "\t";
95 for my $addr ( $patron->findnodes( "Address" ) ) {
96 my $addr_type = $addr->getAttribute('addr_type');
97 $addresses{$addr_type} = $addr;
100 foreach my $t ( 1..3 ) {
101 if ($addresses{$t}) {
102 foreach my $e ( @addr_elements ) {
103 my $v = $addresses{$t}->findvalue( $e );
104 print STDOUT ( $v ? $v : '' ) . "\t";
107 foreach ( @addr_elements ) { print STDOUT "\t"; }
111 my $inactive_barcode1 = '';
112 my $inactive_barcode2 = '';
113 my @barcodes = $patron->findnodes( "barcodes" );
114 for my $i_bc ( $barcodes[0]->findnodes( "barcode" ) ) {
115 my $active = $i_bc->getAttribute('active');
116 if ($active eq "0") {
117 if (! $inactive_barcode1 ) {
118 $inactive_barcode1 = $i_bc->textContent;
120 if (! $inactive_barcode2 ) {
121 $inactive_barcode2 = $i_bc->textContent;
123 warn "Extra barcode (" . $i_bc->textContent . ") for user with id = " . $bc . "\n";
128 print STDOUT "$inactive_barcode1\t$inactive_barcode2";
140 if ($string eq 'NEVER') {
141 my (undef,undef,undef,$d,$m,$y) = localtime();
142 return sprintf('%04d-%02d-%02d', $y + 1920, $m + 1, $d);
143 } elsif (length($string) == 8 && $string =~ /^(\d{4})(\d{2})(\d{2})$/o) {
144 ($y,$m,$d) = ($1,$2,$3);
145 } elsif ($string =~ /(\d+)\D(\d+)\D(\d+)/o) { #looks like it's parsable
146 if ( length($3) > 2 ) { # looks like mm.dd.yyyy
147 if ( $1 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
148 if ($1 > 12 && $1 < 31 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
149 ($y,$m,$d) = ($3,$2,$1);
150 } elsif ($2 > 12 && $2 < 31 && $1 < 13) {
151 ($y,$m,$d) = ($3,$1,$2);
154 } elsif ( length($1) > 3 ) { # format probably yyyy.mm.dd
155 if ( $3 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
156 if ($2 > 12 && $2 < 32 && $3 < 13) { # well, actually it looks like yyyy.dd.mm -- why, I don't konw
157 ($y,$m,$d) = ($1,$3,$2);
158 } elsif ($3 > 12 && $3 < 31 && $2 < 13) {
159 ($y,$m,$d) = ($1,$2,$3);
162 } elsif ( $1 < 99 && $2 < 99 && $3 < 99 && $1 > 0 && $2 > 0 && $3 > 0) {
163 if ($3 < 7) { # probably 2000 or greater, mm.dd.yy
165 if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
167 } elsif ($2 > 12 && $2 < 32 && $1 < 13) {
170 } else { # probably before 2000, mm.dd.yy
172 if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy
174 } elsif ($2 > 12 && $2 < 32 && $1 < 13) {
182 if ($y && $m && $d) {
184 $date = sprintf('%04d-%02d-%-2d',$y, $m, $d)
185 if (new DateTime ( year => $y, month => $m, day => $d ));