Skip to content

Commit

Permalink
Fix doi bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorrell committed Nov 2, 2023
1 parent 2a5302a commit c40be49
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 2 additions & 0 deletions caltechdata_api/caltechdata_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def caltechdata_edit(
data = customize_schema.customize_schema(metadata, schema=schema)
else:
# Authors, force oai PID
if "pids" not in metadata:
metadata["pids"] = {}
metadata["pids"]["oai"] = {
"identifier": f"oai:authors.library.caltech.edu:{idv}",
"provider": "oai",
Expand Down
7 changes: 1 addition & 6 deletions caltechdata_api/caltechdata_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def caltechdata_write(
elif "identifiers" in metadata:
identifiers = metadata["identifiers"]
for identifier in identifiers:
doi = False
if "identifierType" in identifier:
if identifier["identifierType"] == "DOI":
doi = identifier["identifier"]
Expand All @@ -198,17 +199,11 @@ def caltechdata_write(
"identifier": identifier["identifier"],
"provider": "oai",
}
else:
doi = False
elif "scheme" in identifier:
# We have RDM internal metadata
if identifier["scheme"] == "doi":
doi = identifier["identifier"]
prefix = doi.split("/")[0]
else:
doi = False
else:
doi = False
if doi != False:
if prefix == repo_prefix:
pids["doi"] = {
Expand Down
8 changes: 7 additions & 1 deletion caltechdata_api/get_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from datacite import schema43


def get_metadata(idv, production=True, validate=True, emails=False, schema="43"):
def get_metadata(
idv, production=True, validate=True, emails=False, schema="43", token=False
):
# Returns just DataCite metadata or DataCite metadata with emails

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

if token:
headers["Authorization"] = "Bearer %s" % token

response = requests.get(url + idv, headers=headers, verify=verify)
print(response.headers)
if response.status_code != 200:
raise Exception(response.text)
else:
Expand Down
19 changes: 16 additions & 3 deletions edit_osn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse, os, json
import s3fs
import s3fs, requests
from datacite import schema43
from caltechdata_api import caltechdata_edit, get_metadata

Expand All @@ -25,7 +25,20 @@
path = "ini210004tommorrell/" + folder + "/"

idv = args.id[0]
metadata = get_metadata(idv, schema="43")
try:
metadata = get_metadata(idv, schema="43")
except:
url = "https://data.caltech.edu/api/records/"

headers = {
"accept": "application/vnd.datacite.datacite+json",
"Authorization": "Bearer %s" % token,
}

response = requests.get(url + idv +'/draft', headers=headers)
if response.status_code != 200:
raise Exception(response.text)
metadata = response.json()

# Find the files
files = s3.glob(path + "/*")
Expand Down Expand Up @@ -56,6 +69,6 @@
production = True

response = caltechdata_edit(
idv, metadata, token, [], production, "43", publish=True, file_links=file_links
idv, metadata, token, [], production, "43", publish=False, file_links=file_links
)
print(response)

0 comments on commit c40be49

Please sign in to comment.