cleaning up the Evergreen repo area; adding Overlay as an option to Vandelay upload...
[Evergreen.git] / Open-ILS / src / extras / import / user_import.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use Data::Dumper;
5
6 while (<STDIN>) {
7         chomp;
8         my @parts = split '\|';
9 #       @parts = @parts[
10 #                       PRIV_EXP_DATE   CREATION_DATE   PRIV_GRANT_DATE DELINQ_STATUS
11 #                       3,              4,              5,              7,
12 #
13 #                       USER_BARCODE    PROFILE         COUNTY(CAT1)    BIRTH_YEAR
14 #                       10,             12,             13,             15,
15 #
16 #                       HOME_LIB        ZIP             ALTID           ADDRESS1
17 #                       16,             17,             18,             19,
18 #                       
19 #                       ADDRESS2        PHONE           EMAIL           NAME
20 #                       20,             21,             22,             23,
21 #                       
22 #                       NUM_CLAIMED_RETURNED
23 #                       24
24 #       ];
25
26         my $addr = parse_addr(@parts[19,20]);
27
28         $$addr{county} = $parts[13];
29         $$addr{zip} ||= $parts[17];
30
31         print Dumper($addr);
32 }
33
34 sub parse_addr {
35         my $addr1 = shift;
36         my $addr2 = shift;
37
38         $addr1 =~ s/^\s*(.+)\s*$/$1/gso;
39         $addr2 =~ s/^\s*(.+)\s*$/$1/gso;
40
41         $addr1 =~ s/\s+/ /gso;
42         $addr2 =~ s/\s+/ /gso;
43
44         my %hash;
45
46         if ($addr1 =~ /^(\d+\s+[^,]+)/o) {
47                 $hash{address1} = $1;
48                 if ($addr1 =~ /,\s+(.+)$/o) {
49                         my $a2 = $1;
50                         if ($a2 =~ /^(\w{2})\.?\s+(\d+)$/o) {
51                                 $hash{state} = uc($1);
52                                 $hash{zip} = $2;
53                         } elsif (lc($a2) !~ /^(?:s\.?e\.?|s\.?w\.?|n\.?e\.?|n\.?w\.?|south|north|east|west|n\.?|s\.?|e\.?|w\.?)$/) {
54                                 $hash{address2} = $a2;
55                         } else {
56                                 $hash{address1} .= " $a2";
57                         }
58                 }
59         } else {
60                 $hash{address1} = $addr1;
61         }
62
63         if ($addr2 =~ /^([^,]+),\s*(\w{2}).*\s+(\w+)$/o) {
64                 $hash{city} = $1;
65                 $hash{state} = uc($2);
66                 $hash{zip} = $3;
67         }
68
69         return \%hash;
70 }