making the user delete information a bit more robust
[migration-tools.git] / unicorn / unicorn_patrons_to_lostitem_tsv.pl
1 #!/usr/bin/perl -w
2
3 # Copyright 2009-2012, Equinox Software, Inc.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19
20 # Converts a Unicorn users.data file to a tab-separated file of lost items.
21 # 2009-11-06 Ben Ostrowsky <ben@esilibrary.com>
22 #
23 # Output fields:
24 #
25 #   Patron ID
26 #   Item ID
27 #   Item Copy Number
28 #   Due Date
29 #   Title, Author, Call (or parts thereof)
30 #
31
32 my $field = '';
33 my $lostitem = '';
34 my $userid = '';
35
36 # Load each record
37 while (<>) {
38     s/\r\n/\n/g;
39 # print STDERR "Loaded this line: " . $_;
40
41         if ( /^\.(.*?).\s+(\|a)?(.*)$/ ) {
42                 $field = $1;
43                 if ($field eq 'USER_ID') { 
44                         if ($lostitem ne '') { 
45                                 $lostitem =~ m/^(.*)copy:([^,]*),\s*ID:([^,]*),\s*due:(.*)$/;
46                                 print "$userid\t$3\t$2\t$4\t$1\n"; 
47                         }
48                         $userid = $3;
49                         $lostitem = '';
50                 }
51                 if ($field eq 'LOSTITEM') { 
52                         if ($lostitem ne '') { 
53                                 $lostitem =~ m/^(.*)copy:([^,]*),\s*ID:([^,]*),\s*due:(.*)$/;
54                                 print "$userid\t$3\t$2\t$4\t$1\n"; 
55                         }
56                         $lostitem = $3;
57                 } 
58                 next;
59         }       
60
61         # This is the continuation of the previous line.
62         else {
63                 chomp($_);
64                 if ($field eq 'LOSTITEM') { $lostitem .= $_; }
65         }
66
67 }