diff --git a/filter_eod_report.pl b/filter_eod_report.pl new file mode 100755 index 0000000000000000000000000000000000000000..a0831705fbc7333493b3707f29651b12c013bb79 --- /dev/null +++ b/filter_eod_report.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use strict; + +use Data::Dumper; +$Data::Dumper::Indent= 1; + +use Util::Simple_CSV; + +my $fnm_in= shift(@ARGV) || 'eod_data.tsv'; +my $fnm_out= shift(@ARGV) || 'report_bib.tsv'; + +my @columns_copy= qw(ac_number mms_id ticket val_hdl); +my @columns_out= qw(ac_number mms_id alma_fetched ticket url nbn hdl val_hdl); + +my $tsv_in= Util::Simple_CSV->new(load => $fnm_in, separator => "\t"); + +open (TSV_OUT, '>:utf8', $fnm_out) or die; +print TSV_OUT join("\t", @columns_out), "\n"; + +my $data= $tsv_in->{data}; + +# print __LINE__, " data: ", Dumper ($data); +foreach my $row (@$data) +{ + # print __LINE__, " row: ", Dumper ($row); + my ($update_url, $update_urn, $update_hdl, $update_doi)= map { $row->{$_} } qw( update_phaidra_url update_urn update_hdl update_doi ); + # printf ("update_url=[%s] update_urn=[%s] update_hdl=[%s] update_doi=[%s]\n", $update_url, $update_urn, $update_hdl, $update_doi); + + if ($update_url || (0 && $update_urn) || $update_hdl) + { + my %out= map { $_ => $row->{$_} } @columns_copy; + $out{url}= $update_url if (defined ($update_url)); + $out{nbn}= $update_urn if (defined ($update_urn)); + $out{hdl}= $update_hdl if (defined ($update_hdl)); + + $out{alma_fetched}= $row->{ts_fetched}; + $out{hdl}= $row->{hdl} unless ($row->{val_hdl} eq $row->{hdl}); # set handle only when not alreadys set... + + # print __LINE__, " out: ", Dumper(\%out); + print TSV_OUT join("\t", map { $out{$_} } @columns_out), "\n"; + } +} + +