-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateocrpdf
More file actions
executable file
·128 lines (107 loc) · 2.71 KB
/
createocrpdf
File metadata and controls
executable file
·128 lines (107 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env perl
package SyncDMD;
use strict;
use warnings;
use Getopt::Long;
use Data::Dumper;
use JSON;
use utf8;
use Switch;
use URI::Escape;
{
package restclient;
use Moo;
with 'Role::REST::Client';
}
my $couchdb_access;
$couchdb_access = $ENV{COUCHDB_ACCESS}
if ( exists $ENV{COUCHDB_ACCESS} );
my $success;
my $message;
my $usenoids;
GetOptions(
'couchdb_access:s' => \$couchdb_access,
'message:s' => \$message,
'success' => \$success,
'usenoids' => \$usenoids
);
die "couchdb_access is mandatory (environment or parameter)\n"
if ( !$couchdb_access );
$couchdb_access = noEndSlash($couchdb_access);
my $accessdb = new restclient(
server => $couchdb_access,
type => 'application/json',
clientattrs => { timeout => 3600 },
);
$accessdb->set_persistent_header( 'Accept' => 'application/json' );
my $test = $accessdb->head("/");
if ( !$test || $test->code != 200 ) {
die
"Problem connecting to `access` Couchdb database. Check configuration\n";
}
my $command = shift @ARGV;
my $url;
my $data = {};
switch ($command) {
case "request" {
$url = "/_design/metadatabus/_update/requestOCRPDF/";
}
case "cancel" {
$url = "/_design/metadatabus/_update/cancelOCRPDF/";
}
case "update" {
$url = "/_design/metadatabus/_update/updateOCRPDF/";
$data = {
succeeded => $success ? JSON::true : JSON::false,
message => $message
}
}
else { print "First argument command=$command is unknown\n" }
}
if ( !$url ) {
die "No URL to use\n";
}
my @noids;
if ($usenoids) {
@noids = @ARGV;
}
else {
my $uri = "/_design/access/_view/slug";
my $res = $accessdb->post(
$uri,
{
keys => \@ARGV,
include_docs => JSON::false
},
{ deserializer => 'application/json' }
);
if ( $res->code != 201 && $res->code != 200 ) {
warn $uri . " POST return code: " . $res->code . "\n";
}
else {
foreach my $row ( @{ $res->data->{rows} } ) {
if ( defined $row->{id} ) {
push @noids, $row->{id};
}
else {
print Data::Dumper->Dump( [$row], ["SlugLookupRow"] );
}
}
}
}
foreach my $noid (@noids) {
my $uri = $url . uri_escape_utf8($noid);
my $res =
$accessdb->post( $uri, $data, { deserializer => 'application/json' } );
if ( $res->code != 201 && $res->code != 200 ) {
warn $uri . " POST return code: " . $res->code . "\n";
}
else {
print Data::Dumper->Dump( [ $res->data ], [$noid] );
}
}
sub noEndSlash {
my ($url) = @_;
$url =~ s|/*$||;
return $url;
}