New script to extract lost items from users.data, when present
authorBen Ostrowsky <ben@esilibrary.com>
Fri, 6 Nov 2009 16:47:34 +0000 (16:47 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 16 Jul 2012 16:08:41 +0000 (12:08 -0400)
git-svn-id: svn://nox.esilibrary.com/migration-tools@636 eee7cc8d-164e-4af6-8e1b-092a69004917

unicorn/unicorn_patrons_to_lostitem_tsv.pl [new file with mode: 0755]

diff --git a/unicorn/unicorn_patrons_to_lostitem_tsv.pl b/unicorn/unicorn_patrons_to_lostitem_tsv.pl
new file mode 100755 (executable)
index 0000000..96bbf44
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/perl -w
+
+# Converts a Unicorn users.data file to a tab-separated file of lost items.
+# 2009-11-06 Ben Ostrowsky <ben@esilibrary.com>
+#
+# Output fields:
+#
+#   Patron ID
+#   Item ID
+#   Item Copy Number
+#   Due Date
+#   Title, Author, Call (or parts thereof)
+#
+
+my $field = '';
+my $lostitem = '';
+my $userid = '';
+
+# Load each record
+while (<>) {
+    s/\r\n/\n/g;
+# print STDERR "Loaded this line: " . $_;
+
+       if ( /^\.(.*?).\s+(\|a)?(.*)$/ ) {
+               $field = $1;
+               if ($field eq 'USER_ID') { 
+                       if ($lostitem ne '') { 
+                               $lostitem =~ m/^(.*)copy:([^,]*),\s*ID:([^,]*),\s*due:(.*)$/;
+                               print "$userid\t$3\t$2\t$4\t$1\n"; 
+                       }
+                       $userid = $3;
+                       $lostitem = '';
+               }
+               if ($field eq 'LOSTITEM') { 
+                       if ($lostitem ne '') { 
+                               $lostitem =~ m/^(.*)copy:([^,]*),\s*ID:([^,]*),\s*due:(.*)$/;
+                               print "$userid\t$3\t$2\t$4\t$1\n"; 
+                       }
+                       $lostitem = $3;
+               } 
+               next;
+       }       
+
+       # This is the continuation of the previous line.
+       else {
+               chomp($_);
+               if ($field eq 'LOSTITEM') { $lostitem .= $_; }
+       }
+
+}