From 1c2665faa58ba0740b6857a244c1033680aaf006 Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Fri, 24 Mar 2023 19:29:43 +0100
Subject: [PATCH] script to extract data from eod_data.tsv to create a change
 report of UB

---
 filter_eod_report.pl | 45 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100755 filter_eod_report.pl

diff --git a/filter_eod_report.pl b/filter_eod_report.pl
new file mode 100755
index 0000000..a083170
--- /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";
+  }
+}
+
+
-- 
GitLab