Skip to content

Commit 3b52a19

Browse files
committed
Updated HTE script with better DOI management
1 parent 08fbdf5 commit 3b52a19

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

completed_dois.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

write_hte.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import requests
44
from datacite import schema43, DataCiteRESTClient
55
from caltechdata_api import caltechdata_write, caltechdata_edit
6+
from tqdm import tqdm
67

78
folder = "0_gregoire"
89

@@ -59,7 +60,7 @@
5960
for doi in excluded:
6061
records.remove(doi)
6162

62-
for record in records:
63+
for record in tqdm(records):
6364
base = record.split("/")[1]
6465
meta_path = path + base + "/metadata.json"
6566
metadata = None
@@ -195,16 +196,18 @@
195196
s3=s3,
196197
community=community,
197198
)
198-
print(new_id)
199199
url = f"https://data.caltech.edu/records/{new_id}"
200200

201201
# record_ids[old_id] = new_id
202202
# with open("new_ids.json", "w") as outfile:
203203
# json.dump(record_ids, outfile)
204-
205-
doi = datacite.update_doi(doi=record, metadata=metadata, url=url)["doi"]
204+
205+
result = requests.get(f'https://api.datacite.org/dois/{doi}')
206+
if result.status_code != 200:
207+
doi = datacite.public_doi(doi=record, metadata=metadata, url=url)
208+
else:
209+
doi = datacite.update_doi(doi=record, metadata=metadata, url=url)["doi"]
206210
completed.append(doi)
207211
with open("completed_dois.json", "w") as outfile:
208212
data = json.dump(completed, outfile)
209213

210-
exit()

0 commit comments

Comments
 (0)