-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_authors_dupe_check.py
59 lines (46 loc) · 1.59 KB
/
run_authors_dupe_check.py
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
import os, sys
import requests
from ames.harvesters import get_pending_requests, get_records_from_date
from ames.matchers import check_doi
def is_dupe(data, margin):
pids = False
idvn = False
eprints = False
if "pids" in data:
if "doi" in data["pids"]:
doi = data["pids"]["doi"]["identifier"]
if check_doi(doi) > margin:
print(doi, "DUPE", data["id"])
pids = True
if "identifiers" in data["metadata"]:
identifiers = data["metadata"]["identifiers"]
for idv in identifiers:
scheme = idv["scheme"]
if scheme == "doi":
doi = idv["identifier"]
if check_doi(doi) > margin:
print(doi, "DUPE", data["id"])
idvn = True
if scheme == "eprintid":
eprints = True
if pids == False and idvn == False and eprints == False:
print(f"missing DOI for {data['id']}")
token = os.environ["CTATOK"]
community = "aedd135f-227e-4fdf-9476-5b3fd011bac6"
pending = get_pending_requests(token, community, return_ids=True)
base = "https://authors.library.caltech.edu"
url = base + "/api/records/"
headers = {
"Authorization": "Bearer %s" % token,
"Content-type": "application/json",
}
for record in pending:
record_url = url + record + "/draft"
response = requests.get(record_url, headers=headers)
if response.status_code != 200:
print(f"record {record} not found")
data = response.json()
is_dupe(data, 0)
records = get_records_from_date()
for rec in records:
is_dupe(rec, 1)