]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/import/direct_ingest.pl
removing vestigial traces of the old "worm" stuff
[Evergreen.git] / Open-ILS / src / extras / import / direct_ingest.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use lib '/openils/lib/perl5/';
6
7 use OpenSRF::System;
8 use OpenSRF::EX qw/:try/;
9 use OpenSRF::AppSession;
10 use OpenSRF::Application;
11 use OpenSRF::MultiSession;
12 use OpenSRF::Utils::SettingsClient;
13 use OpenILS::Application::Ingest;
14 use OpenILS::Application::AppUtils;
15 use OpenILS::Utils::Fieldmapper;
16 use Digest::MD5 qw/md5_hex/;
17 use OpenSRF::Utils::JSON;
18 use Data::Dumper;
19 use FileHandle;
20
21 use Time::HiRes qw/time/;
22 use Getopt::Long;
23 use MARC::Batch;
24 use MARC::File::XML;
25 use MARC::Charset;
26
27 MARC::Charset->ignore_errors(1);
28
29 my ($auth, $config) =
30         (0, '/openils/conf/opensrf_core.xml');
31
32 GetOptions(
33         'config=s'      => \$config,
34         'authority'     => \$auth,
35 );
36
37 my @ses;
38
39 open NEWERR,     ">&STDERR";
40
41 select NEWERR; $| = 1;
42 select STDERR; $| = 1;
43 select STDOUT; $| = 1;
44
45 OpenSRF::System->bootstrap_client( config_file => $config );
46 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
47
48 OpenILS::Application::Ingest->use;
49
50 my $meth = 'open-ils.ingest.full.biblio.object.readonly';
51 $meth = 'open-ils.ingest.full.authority.object.readonly' if ($auth);
52
53 $meth = OpenILS::Application::Ingest->method_lookup( $meth );
54
55 my $count = 0;
56 my $starttime = time;
57 while (my $rec = <>) {
58         next unless ($rec);
59
60         my $bib = OpenSRF::Utils::JSON->JSON2perl($rec);
61         my $data;
62
63         try {
64                 ($data) = $meth->run( $bib );
65         } catch Error with {
66                 my $e = shift;
67                 warn "Couldn't process record: $e\n >>> $rec\n";
68         };
69
70         next unless $data;
71
72         postprocess( { bib => $bib, ingest_data => $data } );
73
74         if (!($count % 20)) {
75                 print NEWERR "\r$count\t". $count / (time - $starttime);
76         }
77
78         $count++;
79 }
80
81 sub postprocess {
82         my $data = shift;
83
84         my $bib = $data->{bib};
85         my $full_rec = $data->{ingest_data}->{full_rec};
86
87         my $field_entries = $data->{ingest_data}->{field_entries} unless ($auth);
88         my $fp = $data->{ingest_data}->{fingerprint} unless ($auth);
89         my $rd = $data->{ingest_data}->{descriptor} unless ($auth);
90
91         $bib->fingerprint( $fp->{fingerprint} ) unless ($auth);
92         $bib->quality( $fp->{quality} ) unless ($auth);
93
94         print( OpenSRF::Utils::JSON->perl2JSON($bib)."\n" );
95         unless ($auth) {
96                 print( OpenSRF::Utils::JSON->perl2JSON($rd)."\n" );
97                 print( OpenSRF::Utils::JSON->perl2JSON($_)."\n" ) for (@$field_entries);
98         }
99
100         print( OpenSRF::Utils::JSON->perl2JSON($_)."\n" ) for (@$full_rec);
101 }
102