From f0b6e8f49d756121a755f661d7e162feb5699ba8 Mon Sep 17 00:00:00 2001 From: Gerhard Gonter <ggonter@gmail.com> Date: Mon, 27 Mar 2023 19:29:10 +0200 Subject: [PATCH] improved commandline argument handling to provide options for "light" and "heavy" versions of the output --- filter_eod_report.pl | 53 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/filter_eod_report.pl b/filter_eod_report.pl index a083170..3b95735 100755 --- a/filter_eod_report.pl +++ b/filter_eod_report.pl @@ -7,11 +7,46 @@ $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 $detail_level= 1; +# 0 .. only the most necessary things (corrections and new phaira urls) +# 1 .. plus everything that is missing, e.g. added NBNs (urn) or Handles (hdl) -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 @pars= (); +while (defined (my $arg= shift (@ARGV))) +{ + if ($arg eq '-') { push (@pars, '-'); } + elsif ($arg eq '--') { push (@pars, @ARGV); @ARGV= (); } + elsif ($arg =~ /^--(.+)/) + { + my ($opt, $val)= split ('=', $1, 2); + if ($opt eq 'help') { usage(); } + elsif ($opt eq 'heavy') { $detail_level= 1; } + elsif ($opt eq 'light') { $detail_level= 0; } + else { usage(); } + } + elsif ($arg =~ /^-(.+)/) + { + foreach my $opt (split ('', $1)) + { + if ($opt eq 'h') { usage(); exit (0); } + elsif ($opt eq 'H') { $detail_level= 1; } + elsif ($opt eq 'L') { $detail_level= 0; } + else { usage(); } + } + } + else + { + push (@pars, $arg); + } +} + +print join (' ', __FILE__, __LINE__, 'caller=['. caller() . ']'), "\n"; + +my $fnm_in= shift(@pars) || 'eod_data.tsv'; +my $fnm_out= shift(@pars) || 'report_bib_'. (($detail_level) ? 'heavy' : 'light') .'.tsv'; + +my @columns_copy= qw(ac_number mms_id alma_notes ticket val_hdl); +my @columns_out= qw(ac_number mms_id alma_fetched alma_notes ticket url nbn hdl); my $tsv_in= Util::Simple_CSV->new(load => $fnm_in, separator => "\t"); @@ -21,13 +56,14 @@ print TSV_OUT join("\t", @columns_out), "\n"; my $data= $tsv_in->{data}; # print __LINE__, " data: ", Dumper ($data); +my $count= 0; 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) + if ($update_url || ($detail_level && ($update_urn || $update_hdl))) { my %out= map { $_ => $row->{$_} } @columns_copy; $out{url}= $update_url if (defined ($update_url)); @@ -35,11 +71,16 @@ foreach my $row (@$data) $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... + $out{hdl}= $row->{hdl} if (($detail_level == 0 && $row->{val_hdl} ne $row->{hdl}) || $detail_level > 0); # set handle only when not alreadys set... # print __LINE__, " out: ", Dumper(\%out); print TSV_OUT join("\t", map { $out{$_} } @columns_out), "\n"; + $count++; } } +close(TSV); + +print __LINE__, " saved $count records to $fnm_out\n"; + -- GitLab