diff --git a/caltechdata_api/caltechdata_edit.py b/caltechdata_api/caltechdata_edit.py index 65cde78..88d4a00 100644 --- a/caltechdata_api/caltechdata_edit.py +++ b/caltechdata_api/caltechdata_edit.py @@ -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", diff --git a/caltechdata_api/caltechdata_write.py b/caltechdata_api/caltechdata_write.py index 485b2a8..9bd9fd4 100644 --- a/caltechdata_api/caltechdata_write.py +++ b/caltechdata_api/caltechdata_write.py @@ -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"] @@ -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"] = { diff --git a/caltechdata_api/get_metadata.py b/caltechdata_api/get_metadata.py index d728c3d..a371f4f 100644 --- a/caltechdata_api/get_metadata.py +++ b/caltechdata_api/get_metadata.py @@ -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: @@ -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: diff --git a/edit_osn.py b/edit_osn.py index 3a1fd7e..3ab0d2f 100644 --- a/edit_osn.py +++ b/edit_osn.py @@ -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 @@ -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 + "/*") @@ -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)