From 86a6483dcbc8afc774e3e666f360ea940cd6b0d3 Mon Sep 17 00:00:00 2001 From: Shawn Boyette Date: Mon, 9 Feb 2009 19:49:55 +0000 Subject: [PATCH] rename --- csv_extractor | 28 --- csv_ripper | 28 +++ ils-specific/unicorn/unicorn_patron_xml2text.pl | 217 ++++++++++++----------- 3 files changed, 139 insertions(+), 134 deletions(-) delete mode 100755 csv_extractor create mode 100755 csv_ripper diff --git a/csv_extractor b/csv_extractor deleted file mode 100755 index 99e047c..0000000 --- a/csv_extractor +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/perl - -# TODO -# -# * add getopt support -# * use tag generator to expand list of wanted fields? -# * insertion of constant-value fields -# * field mapping ("some text" -> 4)? - -# csv-extractor FILENAME FIELD_LIST - -use strict; -use warnings; - -use Text::CSV; - -my $csv = Text::CSV->new({escape_char => "+", allow_loose_quotes => 1}); - -open CSV, '<', shift or die "Can't open file $!\n"; - -while () { - $csv->parse($_); - my @chunks = $csv->fields; - my @out = (); - for (@ARGV) - { push @out, $chunks[$_]} - print join("\t", @out), "\n"; -} diff --git a/csv_ripper b/csv_ripper new file mode 100755 index 0000000..99e047c --- /dev/null +++ b/csv_ripper @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +# TODO +# +# * add getopt support +# * use tag generator to expand list of wanted fields? +# * insertion of constant-value fields +# * field mapping ("some text" -> 4)? + +# csv-extractor FILENAME FIELD_LIST + +use strict; +use warnings; + +use Text::CSV; + +my $csv = Text::CSV->new({escape_char => "+", allow_loose_quotes => 1}); + +open CSV, '<', shift or die "Can't open file $!\n"; + +while () { + $csv->parse($_); + my @chunks = $csv->fields; + my @out = (); + for (@ARGV) + { push @out, $chunks[$_]} + print join("\t", @out), "\n"; +} diff --git a/ils-specific/unicorn/unicorn_patron_xml2text.pl b/ils-specific/unicorn/unicorn_patron_xml2text.pl index 97149c8..296bf54 100755 --- a/ils-specific/unicorn/unicorn_patron_xml2text.pl +++ b/ils-specific/unicorn/unicorn_patron_xml2text.pl @@ -16,7 +16,7 @@ my $count = 1; my @base_elements = ( "user_id", "user_altid", - "user_pin", +# "user_pin", "user_profile", "user_status", "user_library", @@ -29,24 +29,28 @@ my @base_elements = ( "middle_name", "suffix_name", "note", - "note1", +# "note1", + "patron", "comment", - "staff", - "webcatpref", +# "staff", +# "webcatpref", "user_category1", - "user_category2", +# "user_category2", "user_category3", - "user_category4", - "dept", - "guardian", - "license", - "aup", - "photo", - "notify_via", - "user_claims_ret", - "user_environment", - "user_department", - "ums_id" +# "user_category4", +# "dept", +# "guardian", +# "license", + # "aup", +# "photo", +# "notify_via", +# "user_claims_ret", +# "user_environment", +# "user_department", + "ums_id", + "user_last_activity", + "placcard", + "user_email", ); my @addr_elements = ( @@ -55,16 +59,17 @@ my @addr_elements = ( "std_city", "std_state", "std_zip", - "phone", - "dayphone", +# "phone", +# "dayphone", "homephone", - "workphone", - "cellphone", - "email", - "location", - "usefor", - "care_of", - "known_bad" +# "workphone", +# "cellphone", +# "email", +# "location", +# "usefor", +# "care_of", +# "known_bad", + "ums_addrid", ); print STDOUT join("\t", @base_elements); @@ -75,37 +80,37 @@ print STDOUT "\tuserid_active\tinactive_barcode1\tinactive_barcode2"; print STDOUT "\n"; for my $patron ( $doc->documentElement->childNodes ) { - next if ($patron->nodeType == 3); - - my $bc = $patron->findvalue( 'user_id' ); $bc =~ s/^\s+//; $bc =~ s/\s+$//; - if (exists($s_map{$bc})) { - $count++; - warn "\n!!! already saw barcode $bc, skipping\n"; - next; - } else { - $s_map{$bc} = 1; - } - - unless (defined($bc)) { - my $xml = $patron->toString; - warn "\n!!! no barcode found in UMS data, user number $count, xml => $xml \n"; - $count++; - next; - } - + next if ($patron->nodeType == 3); + + my $bc = $patron->findvalue( 'user_id' ); $bc =~ s/^\s+//; $bc =~ s/\s+$//; + if (exists($s_map{$bc})) { + $count++; + warn "\n!!! already saw barcode $bc, skipping\n"; + next; + } else { + $s_map{$bc} = 1; + } + + unless (defined($bc)) { + my $xml = $patron->toString; + warn "\n!!! no barcode found in UMS data, user number $count, xml => $xml \n"; + $count++; + next; + } + foreach my $e ( @base_elements ) { my $v = $patron->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//; if ( $v && ( $e eq 'birthdate' || $e eq 'user_priv_granted' || $e eq 'user_priv_expires' ) ) { $v = parse_date($v); } print STDOUT ( $v ? $v : '' ) . "\t"; } - my %addresses; - - for my $addr ( $patron->findnodes( "Address" ) ) { - my $addr_type = $addr->getAttribute('addr_type'); - $addresses{$addr_type} = $addr; - } - + my %addresses; + + for my $addr ( $patron->findnodes( "Address" ) ) { + my $addr_type = $addr->getAttribute('addr_type'); + $addresses{$addr_type} = $addr; + } + foreach my $t ( 1..3 ) { if ($addresses{$t}) { foreach my $e ( @addr_elements ) { @@ -121,7 +126,7 @@ for my $patron ( $doc->documentElement->childNodes ) { foreach ( @addr_elements ) { print STDOUT "\t"; } } } - + my $inactive_barcode1 = ''; my $inactive_barcode2 = ''; my $userid_active = 't'; @@ -154,60 +159,60 @@ for my $patron ( $doc->documentElement->childNodes ) { } sub parse_date { - my $string = shift; - my $group = shift; - - my ($y,$m,$d); - - if ($string eq 'NEVER') { - my (undef,undef,undef,$d,$m,$y) = localtime(); - return sprintf('%04d-%02d-%02d', $y + 1920, $m + 1, $d); - } elsif (length($string) == 8 && $string =~ /^(\d{4})(\d{2})(\d{2})$/o) { - ($y,$m,$d) = ($1,$2,$3); - } elsif ($string =~ /(\d+)\D(\d+)\D(\d+)/o) { #looks like it's parsable - if ( length($3) > 2 ) { # looks like mm.dd.yyyy - if ( $1 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { - if ($1 > 12 && $1 < 31 && $2 < 13) { # well, actually it looks like dd.mm.yyyy - ($y,$m,$d) = ($3,$2,$1); - } elsif ($2 > 12 && $2 < 31 && $1 < 13) { - ($y,$m,$d) = ($3,$1,$2); - } - } - } elsif ( length($1) > 3 ) { # format probably yyyy.mm.dd - if ( $3 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { - if ($2 > 12 && $2 < 32 && $3 < 13) { # well, actually it looks like yyyy.dd.mm -- why, I don't konw - ($y,$m,$d) = ($1,$3,$2); - } elsif ($3 > 12 && $3 < 31 && $2 < 13) { - ($y,$m,$d) = ($1,$2,$3); - } - } - } elsif ( $1 < 99 && $2 < 99 && $3 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { - if ($3 < 7) { # probably 2000 or greater, mm.dd.yy - $y = $3 + 2000; - if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy - ($m,$d) = ($2,$1); - } elsif ($2 > 12 && $2 < 32 && $1 < 13) { - ($m,$d) = ($1,$2); - } - } else { # probably before 2000, mm.dd.yy - $y = $3 + 1900; - if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy - ($m,$d) = ($2,$1); - } elsif ($2 > 12 && $2 < 32 && $1 < 13) { - ($m,$d) = ($1,$2); - } - } - } - } - - my $date = $string; - if ($y && $m && $d) { - eval { - $date = sprintf('%04d-%02d-%-2d',$y, $m, $d) - if (new DateTime ( year => $y, month => $m, day => $d )); - } - } - - return $date; + my $string = shift; + my $group = shift; + + my ($y,$m,$d); + + if ($string eq 'NEVER') { + my (undef,undef,undef,$d,$m,$y) = localtime(); + return sprintf('%04d-%02d-%02d', $y + 1920, $m + 1, $d); + } elsif (length($string) == 8 && $string =~ /^(\d{4})(\d{2})(\d{2})$/o) { + ($y,$m,$d) = ($1,$2,$3); + } elsif ($string =~ /(\d+)\D(\d+)\D(\d+)/o) { #looks like it's parsable + if ( length($3) > 2 ) { # looks like mm.dd.yyyy + if ( $1 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { + if ($1 > 12 && $1 < 31 && $2 < 13) { # well, actually it looks like dd.mm.yyyy + ($y,$m,$d) = ($3,$2,$1); + } elsif ($2 > 12 && $2 < 31 && $1 < 13) { + ($y,$m,$d) = ($3,$1,$2); + } + } + } elsif ( length($1) > 3 ) { # format probably yyyy.mm.dd + if ( $3 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { + if ($2 > 12 && $2 < 32 && $3 < 13) { # well, actually it looks like yyyy.dd.mm -- why, I don't konw + ($y,$m,$d) = ($1,$3,$2); + } elsif ($3 > 12 && $3 < 31 && $2 < 13) { + ($y,$m,$d) = ($1,$2,$3); + } + } + } elsif ( $1 < 99 && $2 < 99 && $3 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { + if ($3 < 7) { # probably 2000 or greater, mm.dd.yy + $y = $3 + 2000; + if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy + ($m,$d) = ($2,$1); + } elsif ($2 > 12 && $2 < 32 && $1 < 13) { + ($m,$d) = ($1,$2); + } + } else { # probably before 2000, mm.dd.yy + $y = $3 + 1900; + if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy + ($m,$d) = ($2,$1); + } elsif ($2 > 12 && $2 < 32 && $1 < 13) { + ($m,$d) = ($1,$2); + } + } + } + } + + my $date = $string; + if ($y && $m && $d) { + eval { + $date = sprintf('%04d-%02d-%-2d',$y, $m, $d) + if (new DateTime ( year => $y, month => $m, day => $d )); + } + } + + return $date; } -- 1.7.2.5