more unicorn conversion tools
authorJason Etheridge <jason@esilibrary.com>
Fri, 25 Jul 2008 19:20:05 +0000 (19:20 +0000)
committerJason Etheridge <jason@esilibrary.com>
Fri, 25 Jul 2008 19:20:05 +0000 (19:20 +0000)
transform_unicorn_flat_bills.pl [new file with mode: 0755]
transform_unicorn_flat_charges.pl [new file with mode: 0755]

diff --git a/transform_unicorn_flat_bills.pl b/transform_unicorn_flat_bills.pl
new file mode 100755 (executable)
index 0000000..a754bff
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/perl -w
+
+my $count = 0;
+my %records = ();
+
+sub print_line {
+    print join("\t",
+        $records{ $count }{'FORM'} || '',
+        $records{ $count }{'USER_ID'} || '',
+        $records{ $count }{'ITEM_ID'} || '',
+        $records{ $count }{'BILL_LIBRARY'} || '',
+        $records{ $count }{'BILL_DB'} || '',
+        $records{ $count }{'BILL_AMOUNT'} || '',
+        $records{ $count }{'BILL_REASON'} || '',
+    ) . "\n"; 
+}
+
+print "FORM\tUSER_ID\tITEM_ID\tBILL_LIBRARY\tBILL_DB\tBILL_AMOUNT\tBILL_REASON\n";
+
+while (my $line = <>) {
+    chomp $line; $line =~ s/[\r\n]//g;
+    if ($line =~ /DOCUMENT BOUNDARY/) {
+        if (defined $records{ $count }) {
+            print_line();
+        }
+        $count++; $records{ $count } = {};
+    }
+    if ($line =~ /FORM=(.+)/) {
+        $records{ $count }{'FORM'} = $1;
+    }
+    if ($line =~ /\.USER_ID\..+\|a(.+)/) {
+        $records{ $count }{'USER_ID'} = $1;
+    }
+    if ($line =~ /\.ITEM_ID\..+\|a(.+)/) {
+        $records{ $count }{'ITEM_ID'} = $1;
+    }
+    if ($line =~ /\.BILL_LIBRARY\..+\|a(.+)/) {
+        $records{ $count }{'BILL_LIBRARY'} = $1;
+    }
+    if ($line =~ /\.BILL_DB\..+\|a(.+)/) {
+        $records{ $count }{'BILL_DB'} = $1;
+    }
+    if ($line =~ /\.BILL_AMOUNT\..+\|a(.+)/) {
+        $records{ $count }{'BILL_AMOUNT'} = $1;
+    }
+    if ($line =~ /\.BILL_REASON\..+\|a(.+)/) {
+        $records{ $count }{'BILL_REASON'} = $1;
+    }
+}
+print_line();
+
diff --git a/transform_unicorn_flat_charges.pl b/transform_unicorn_flat_charges.pl
new file mode 100755 (executable)
index 0000000..18b8d71
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/perl -w
+
+my $count = 0;
+my %records = ();
+
+sub print_line {
+    print join("\t",
+        $records{ $count }{'FORM'} || '',
+        $records{ $count }{'USER_ID'} || '',
+        $records{ $count }{'ITEM_ID'} || '',
+        $records{ $count }{'CHRG_LIBRARY'} || '',
+        $records{ $count }{'CHRG_DC'} || '',
+        $records{ $count }{'CHRG_DATEDUE'} || '',
+    ) . "\n"; 
+}
+
+print "FORM\tUSER_ID\tITEM_ID\tCHRG_LIBRARY\tCHRG_DC\tCHRG_DATEDUE\n";
+
+while (my $line = <>) {
+    chomp $line; $line =~ s/[\r\n]//g;
+    if ($line =~ /DOCUMENT BOUNDARY/) {
+        if (defined $records{ $count }) {
+            print_line();
+        }
+        $count++; $records{ $count } = {};
+    }
+    if ($line =~ /FORM=(.+)/) {
+        $records{ $count }{'FORM'} = $1;
+    }
+    if ($line =~ /\.USER_ID\..+\|a(.+)/) {
+        $records{ $count }{'USER_ID'} = $1;
+    }
+    if ($line =~ /\.ITEM_ID\..+\|a(.+)/) {
+        $records{ $count }{'ITEM_ID'} = $1;
+    }
+    if ($line =~ /\.CHRG_LIBRARY\..+\|a(.+)/) {
+        $records{ $count }{'CHRG_LIBRARY'} = $1;
+    }
+    if ($line =~ /\.CHRG_DC\..+\|a(.+)/) {
+        $records{ $count }{'CHRG_DC'} = $1;
+    }
+    if ($line =~ /\.CHRG_DATEDUE\..+\|a(.+)/) {
+        $records{ $count }{'CHRG_DATEDUE'} = $1;
+    }
+}
+print_line();
+