forked from USGCRP/gcis-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-article-pg-vol.pl
More file actions
executable file
·79 lines (69 loc) · 1.93 KB
/
fix-article-pg-vol.pl
File metadata and controls
executable file
·79 lines (69 loc) · 1.93 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
#!/usr/bin/env perl
use Data::Dumper;
use Gcis::Client;
use CrossRef;
use strict;
use v5.14;
use warnings;
my $url = "https://data.gcis-dev-front.joss.ucar.edu";
my $dry_run = 0;
my $max_updates = 100;
my $do_all = 1;
&main;
sub main {
my $g = $dry_run ? Gcis::Client->new(url => $url)
: Gcis::Client->connect(url => $url);
my $cr = CrossRef->new;
my $v = "/article";
$v .= "?all=1" if $do_all;
my @l = $g->get($v) or die " unable to get articles";
my $n = @l;
say " articles : $n\n";
my $n_updates = 0;
for my $a (@l) {
last if $max_updates > -1 && $n_updates >= $max_updates;
next unless $a->{doi};
my $u = $a->{uri};
next if $a->{journal_vol} && $a->{journal_pages};
my $c = $cr->get($a->{doi}) or do {
say " doi not in crossref : $u";
next;
};
if (!$c->{title}[0]) {
say " title not in crossref : $u";
next;
}
if (lc $a->{title} ne lc $c->{title}[0]) {
say " titles do not match : $u";
say " gcis : $a->{title}";
say " crossref : $c->{title}[0]";
next;
}
my %check = (
journal_vol => qw(^\d+),
journal_pages => qw(^\d+-\d+$),
);
my $new = 0;
for (qw(journal_vol journal_pages)) {
next unless $c->{$_};
next unless $c->{$_} =~ /$check{$_}/;
if ($a->{$_}) {
next if $a->{$_} eq $c->{$_};
}
$a->{$_} = $c->{$_};
$new++;
}
next unless $new;
if ($dry_run) {
say " would update : $u";
$n_updates++;
next;
}
say " updating : $u";
delete $a->{$_} for qw(uri href);
$n_updates++;
$g->post($u, $a) or die " unable to add : $u";
}
say "\n number updates : $n_updates";
return;
}