adding some basic scripts for cleaning up text from mandarin pdf reprots to make...
[migration-tools.git] / mandarin / clean_mandarin_fine_list_report.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 # copy and paste raw text from acrobat reader to .txt file
7
8 my $filename = $ARGV[0];
9 open(my $fh, '<:encoding(UTF-8)', $filename)
10   or die "Could not open file '$filename' $!";
11
12 my $user;
13  
14 while (my $row = <$fh>) {
15   chomp $row;
16   if ($row =~ m/Fines Due by patron/) { next; }
17   if ($row =~ m/Patron Title Barcode Date Due Fine/) { next; }
18   if ($row =~ m/Page: /) { next; }
19   if ($row =~ m/Program Files \(x86\)/) { next; }
20   if ($row =~ m/End Of Report/) { next; }
21   if ($row =~ m/Fines Due by Patron/) { next; }
22
23   my @str = split / /, $row;
24   my $str_length = scalar(@str);
25   if ($str[1] eq 'AM' or $str[1] eq 'PM') {
26     if ($str[2] =~ m/2019/) { next; }   
27   }
28
29   if ($str[$str_length -1] !~ m/^\d*\.?\d*$/) {
30     $user = $str[$str_length -1];
31     next;
32   }
33
34   #print "$row\n";
35   if ($str[$str_length -1] =~  m/^\d*\.?\d*$/) {
36     my $f = $str[$str_length -1];  #fine
37     my $i = $str[$str_length -3];  #item barcode 
38     print "$user\t$i\t$f\n";
39   } 
40 }