Skip to content

Commit c40be49

Browse files
committed
Fix doi bug
1 parent 2a5302a commit c40be49

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

caltechdata_api/caltechdata_edit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ def caltechdata_edit(
225225
data = customize_schema.customize_schema(metadata, schema=schema)
226226
else:
227227
# Authors, force oai PID
228+
if "pids" not in metadata:
229+
metadata["pids"] = {}
228230
metadata["pids"]["oai"] = {
229231
"identifier": f"oai:authors.library.caltech.edu:{idv}",
230232
"provider": "oai",

caltechdata_api/caltechdata_write.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def caltechdata_write(
189189
elif "identifiers" in metadata:
190190
identifiers = metadata["identifiers"]
191191
for identifier in identifiers:
192+
doi = False
192193
if "identifierType" in identifier:
193194
if identifier["identifierType"] == "DOI":
194195
doi = identifier["identifier"]
@@ -198,17 +199,11 @@ def caltechdata_write(
198199
"identifier": identifier["identifier"],
199200
"provider": "oai",
200201
}
201-
else:
202-
doi = False
203202
elif "scheme" in identifier:
204203
# We have RDM internal metadata
205204
if identifier["scheme"] == "doi":
206205
doi = identifier["identifier"]
207206
prefix = doi.split("/")[0]
208-
else:
209-
doi = False
210-
else:
211-
doi = False
212207
if doi != False:
213208
if prefix == repo_prefix:
214209
pids["doi"] = {

caltechdata_api/get_metadata.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from datacite import schema43
88

99

10-
def get_metadata(idv, production=True, validate=True, emails=False, schema="43"):
10+
def get_metadata(
11+
idv, production=True, validate=True, emails=False, schema="43", token=False
12+
):
1113
# Returns just DataCite metadata or DataCite metadata with emails
1214

1315
if production == True:
@@ -21,7 +23,11 @@ def get_metadata(idv, production=True, validate=True, emails=False, schema="43")
2123
"accept": "application/vnd.datacite.datacite+json",
2224
}
2325

26+
if token:
27+
headers["Authorization"] = "Bearer %s" % token
28+
2429
response = requests.get(url + idv, headers=headers, verify=verify)
30+
print(response.headers)
2531
if response.status_code != 200:
2632
raise Exception(response.text)
2733
else:

edit_osn.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import argparse, os, json
2-
import s3fs
2+
import s3fs, requests
33
from datacite import schema43
44
from caltechdata_api import caltechdata_edit, get_metadata
55

@@ -25,7 +25,20 @@
2525
path = "ini210004tommorrell/" + folder + "/"
2626

2727
idv = args.id[0]
28-
metadata = get_metadata(idv, schema="43")
28+
try:
29+
metadata = get_metadata(idv, schema="43")
30+
except:
31+
url = "https://data.caltech.edu/api/records/"
32+
33+
headers = {
34+
"accept": "application/vnd.datacite.datacite+json",
35+
"Authorization": "Bearer %s" % token,
36+
}
37+
38+
response = requests.get(url + idv +'/draft', headers=headers)
39+
if response.status_code != 200:
40+
raise Exception(response.text)
41+
metadata = response.json()
2942

3043
# Find the files
3144
files = s3.glob(path + "/*")
@@ -56,6 +69,6 @@
5669
production = True
5770

5871
response = caltechdata_edit(
59-
idv, metadata, token, [], production, "43", publish=True, file_links=file_links
72+
idv, metadata, token, [], production, "43", publish=False, file_links=file_links
6073
)
6174
print(response)

0 commit comments

Comments
 (0)