a script to parse TLC items-out reports, initially for Butler Public in Indiana
authorMike Rylander <miker@esilibrary.com>
Sat, 6 Dec 2008 22:13:09 +0000 (22:13 +0000)
committerMike Rylander <miker@esilibrary.com>
Sat, 6 Dec 2008 22:13:09 +0000 (22:13 +0000)
parse-tlc-items-out.pl [new file with mode: 0644]

diff --git a/parse-tlc-items-out.pl b/parse-tlc-items-out.pl
new file mode 100644 (file)
index 0000000..2cee130
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+
+# This parses TCL items-out reports converted from excel to csv, turning them
+# into a tab separated file.  arg!
+
+my $state;
+my $patron;
+my $item;
+my $out;
+my $due;
+my $price;
+
+my ($a,$b,$c,$d,$e,$f,$g) = (0,1,2,3,4,5,6,7);
+
+print "patron\titem\tout\tdue\tprice\n";
+
+while (<>) {
+    chomp;
+    my @fields = split /\t/;
+
+    if ( (!$state || $state eq 'item' || $state eq 'none') && $fields[$f] eq 'Borrower ID') {
+        $state = 'borrower';
+        next;
+    }
+
+    if ($state eq 'borrower') {
+        $patron = $fields[$f];
+        $state = 'none';
+        next;
+    }
+
+    if ($state eq 'none' && $fields[$b] eq 'Item ID') {
+        $state = 'item';
+        next;
+    }
+
+    if ($state eq 'item' && $fields[$b] =~ /^\d+$/o) {
+        $item = $fields[$b];
+        if ($fields[$f] =~ /^(\d+)\/(\d+)\/(\d+)$/) {
+            $out = sprintf('%04d-%02d-%02d', 2000 + $3, $1, $2);
+        }
+        if ($fields[$e] =~ /^(\d+)\/(\d+)\/(\d+)$/) {
+            $due = sprintf('%04d-%02d-%02d', 2000 + $3, $1, $2);
+        }
+        ($price = $fields[$g]) =~ s/\*//go;
+        print join("\t", $patron, $item, $out, $due, $price) . "\n";
+    }
+}