caltechdata-api 1.8.0__tar.gz → 1.8.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/PKG-INFO +1 -1
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/cli.py +26 -14
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/customize_schema.py +2 -20
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/get_metadata.py +29 -8
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api.egg-info/PKG-INFO +1 -1
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/LICENSE +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/README.md +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/__init__.py +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/caltechdata_edit.py +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/caltechdata_write.py +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/download_file.py +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/get_files.py +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/md_to_json.py +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api/utils.py +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api.egg-info/SOURCES.txt +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api.egg-info/dependency_links.txt +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api.egg-info/entry_points.txt +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api.egg-info/requires.txt +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api.egg-info/top_level.txt +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/setup.cfg +0 -0
- {caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/setup.py +0 -0
|
@@ -71,6 +71,11 @@ def get_or_set_token(production=True):
|
|
|
71
71
|
with open(token_file, "rb") as f:
|
|
72
72
|
encrypted_token = f.read()
|
|
73
73
|
token = decrypt_token(encrypted_token, key)
|
|
74
|
+
print(
|
|
75
|
+
"Using saved CaltechDATA production token."
|
|
76
|
+
if production
|
|
77
|
+
else "Using saved CaltechDATA test token."
|
|
78
|
+
)
|
|
74
79
|
return token
|
|
75
80
|
except FileNotFoundError:
|
|
76
81
|
while True:
|
|
@@ -140,7 +145,7 @@ def get_funding_entries():
|
|
|
140
145
|
def validate_funder_identifier(funder_identifier):
|
|
141
146
|
response = requests.get(f"https://api.ror.org/organizations/{funder_identifier}")
|
|
142
147
|
if response.status_code == 200:
|
|
143
|
-
return
|
|
148
|
+
return response.json().get("name")
|
|
144
149
|
else:
|
|
145
150
|
return False
|
|
146
151
|
|
|
@@ -157,7 +162,8 @@ def get_funding_details():
|
|
|
157
162
|
award_title = get_user_input("Enter the award title for funding: ")
|
|
158
163
|
while True:
|
|
159
164
|
funder_identifier = get_user_input("Enter the funder ROR (https://ror.org): ")
|
|
160
|
-
|
|
165
|
+
name = validate_funder_identifier(funder_identifier)
|
|
166
|
+
if name:
|
|
161
167
|
break
|
|
162
168
|
else:
|
|
163
169
|
print(
|
|
@@ -169,6 +175,7 @@ def get_funding_details():
|
|
|
169
175
|
return {
|
|
170
176
|
"awardNumber": award_number,
|
|
171
177
|
"awardTitle": award_title,
|
|
178
|
+
"funderName": name,
|
|
172
179
|
"funderIdentifier": funder_identifier,
|
|
173
180
|
"funderIdentifierType": "ROR",
|
|
174
181
|
}
|
|
@@ -194,9 +201,18 @@ def parse_arguments():
|
|
|
194
201
|
if license_number.isdigit() and 1 <= int(license_number) <= 8:
|
|
195
202
|
# Valid license number selected
|
|
196
203
|
args["license"] = {
|
|
197
|
-
"1":
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
"1": {
|
|
205
|
+
"rights": "Creative Commons Zero v1.0 Universal",
|
|
206
|
+
"rightsIdentifier": "cc0-1.0",
|
|
207
|
+
},
|
|
208
|
+
"2": {
|
|
209
|
+
"rights": "Creative Commons Attribution v4.0 Universal",
|
|
210
|
+
"rightsIdentifier": "cc-by-4.0",
|
|
211
|
+
},
|
|
212
|
+
"3": {
|
|
213
|
+
"rights": "Creative Commons Attribution Non-Commercial v4.0 Universal",
|
|
214
|
+
"rightsIdentifier": "cc-by-nc-4.0",
|
|
215
|
+
},
|
|
200
216
|
}[license_number]
|
|
201
217
|
break
|
|
202
218
|
else:
|
|
@@ -259,9 +275,11 @@ def get_names(orcid):
|
|
|
259
275
|
return family_name, given_name
|
|
260
276
|
|
|
261
277
|
|
|
262
|
-
def write_s3cmd_config(
|
|
278
|
+
def write_s3cmd_config(endpoint):
|
|
263
279
|
configf = os.path.join(home_directory, ".s3cfg")
|
|
264
280
|
if not os.path.exists(configf):
|
|
281
|
+
access_key = get_user_input("Enter the access key: ")
|
|
282
|
+
secret_key = get_user_input("Enter the secret key: ")
|
|
265
283
|
with open(configf, "w") as file:
|
|
266
284
|
file.write(
|
|
267
285
|
f"""[default]
|
|
@@ -286,9 +304,7 @@ def upload_supporting_file(record_id=None):
|
|
|
286
304
|
endpoint = "sdsc.osn.xsede.org"
|
|
287
305
|
path = "ini230004-bucket01/"
|
|
288
306
|
if not record_id:
|
|
289
|
-
|
|
290
|
-
secret_key = get_user_input("Enter the secret key: ")
|
|
291
|
-
write_s3cmd_config(access_key, secret_key, endpoint)
|
|
307
|
+
write_s3cmd_config(endpoint)
|
|
292
308
|
print("""S3 connection configured.""")
|
|
293
309
|
break
|
|
294
310
|
endpoint = f"https://{endpoint}/"
|
|
@@ -411,8 +427,6 @@ def main():
|
|
|
411
427
|
|
|
412
428
|
def create_record(production):
|
|
413
429
|
token = get_or_set_token(production)
|
|
414
|
-
# keep_file = input("Do you want to keep your existing files? (yes/no): ").lower() == "yes"
|
|
415
|
-
print("Using CaltechDATA token:", token)
|
|
416
430
|
while True:
|
|
417
431
|
choice = get_user_input(
|
|
418
432
|
"Do you want to use metadata from an existing file or create new metadata? (existing/create): "
|
|
@@ -478,9 +492,7 @@ def create_record(production):
|
|
|
478
492
|
],
|
|
479
493
|
"types": {"resourceType": "", "resourceTypeGeneral": "Dataset"},
|
|
480
494
|
"rightsList": [
|
|
481
|
-
|
|
482
|
-
"rightsIdentifier": args["license"],
|
|
483
|
-
}
|
|
495
|
+
args["license"],
|
|
484
496
|
],
|
|
485
497
|
"fundingReferences": args["fundingReferences"],
|
|
486
498
|
"schemaVersion": "http://datacite.org/schema/kernel-4",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
# Convert a DataCite 4
|
|
2
|
-
# schema used by TIND in CaltechDATA
|
|
1
|
+
# Convert a DataCite 4.3 standard schema json record to the InvenioRDM schema
|
|
3
2
|
import argparse
|
|
4
3
|
import json
|
|
5
4
|
from datetime import date
|
|
@@ -415,24 +414,7 @@ def validate_metadata(json_record):
|
|
|
415
414
|
"Each entry in 'titles' must be a dictionary with a 'title' key."
|
|
416
415
|
)
|
|
417
416
|
|
|
418
|
-
#
|
|
419
|
-
if "publicationYear" not in json_record and "dates" not in json_record:
|
|
420
|
-
errors.append(
|
|
421
|
-
"A publication date is required ('publicationYear' or 'dates' field is missing)."
|
|
422
|
-
)
|
|
423
|
-
if "dates" in json_record:
|
|
424
|
-
if not isinstance(json_record["dates"], list):
|
|
425
|
-
errors.append("'dates' should be a list.")
|
|
426
|
-
else:
|
|
427
|
-
for date_entry in json_record["dates"]:
|
|
428
|
-
if (
|
|
429
|
-
not isinstance(date_entry, dict)
|
|
430
|
-
or "dateType" not in date_entry
|
|
431
|
-
or "date" not in date_entry
|
|
432
|
-
):
|
|
433
|
-
errors.append(
|
|
434
|
-
"Each entry in 'dates' must be a dictionary with 'dateType' and 'date' keys."
|
|
435
|
-
)
|
|
417
|
+
# Publication date is handled by customize function
|
|
436
418
|
|
|
437
419
|
# Check for 'creators'
|
|
438
420
|
if "creators" not in json_record:
|
|
@@ -8,26 +8,43 @@ from datacite import schema43
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def get_metadata(
|
|
11
|
-
idv,
|
|
11
|
+
idv,
|
|
12
|
+
production=True,
|
|
13
|
+
validate=True,
|
|
14
|
+
emails=False,
|
|
15
|
+
schema="43",
|
|
16
|
+
token=False,
|
|
17
|
+
authors=False,
|
|
12
18
|
):
|
|
13
19
|
# Returns just DataCite metadata or DataCite metadata with emails
|
|
14
20
|
|
|
15
21
|
if production == True:
|
|
16
|
-
|
|
22
|
+
if authors:
|
|
23
|
+
url = "https://authors.library.caltech.edu/api/records/"
|
|
24
|
+
else:
|
|
25
|
+
url = "https://data.caltech.edu/api/records/"
|
|
17
26
|
verify = True
|
|
18
27
|
else:
|
|
19
|
-
|
|
28
|
+
if authors:
|
|
29
|
+
url = "https://authors.caltechlibrary.dev/api/records/"
|
|
30
|
+
else:
|
|
31
|
+
url = "https://data.caltechlibrary.dev/api/records/"
|
|
20
32
|
verify = True
|
|
21
33
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
if authors:
|
|
35
|
+
headers = {
|
|
36
|
+
"accept": "application/json",
|
|
37
|
+
}
|
|
38
|
+
validate = False
|
|
39
|
+
else:
|
|
40
|
+
headers = {
|
|
41
|
+
"accept": "application/vnd.datacite.datacite+json",
|
|
42
|
+
}
|
|
25
43
|
|
|
26
44
|
if token:
|
|
27
45
|
headers["Authorization"] = "Bearer %s" % token
|
|
28
46
|
|
|
29
47
|
response = requests.get(url + idv, headers=headers, verify=verify)
|
|
30
|
-
print(response.headers)
|
|
31
48
|
if response.status_code != 200:
|
|
32
49
|
raise Exception(response.text)
|
|
33
50
|
else:
|
|
@@ -59,6 +76,7 @@ if __name__ == "__main__":
|
|
|
59
76
|
help="The CaltechDATA ID for each record of interest",
|
|
60
77
|
)
|
|
61
78
|
parser.add_argument("-test", dest="production", action="store_false")
|
|
79
|
+
parser.add_argument("-authors", dest="authors", action="store_true")
|
|
62
80
|
parser.add_argument("-xml", dest="save_xml", action="store_true")
|
|
63
81
|
parser.add_argument(
|
|
64
82
|
"-skip_validate",
|
|
@@ -72,6 +90,7 @@ if __name__ == "__main__":
|
|
|
72
90
|
|
|
73
91
|
production = args.production
|
|
74
92
|
schema = args.schema
|
|
93
|
+
authors = args.authors
|
|
75
94
|
skip_validate = args.skip_validate
|
|
76
95
|
if skip_validate:
|
|
77
96
|
validate = False
|
|
@@ -79,7 +98,9 @@ if __name__ == "__main__":
|
|
|
79
98
|
validate = True
|
|
80
99
|
|
|
81
100
|
for idv in args.ids:
|
|
82
|
-
metadata = get_metadata(
|
|
101
|
+
metadata = get_metadata(
|
|
102
|
+
idv, production, validate, schema=schema, authors=authors
|
|
103
|
+
)
|
|
83
104
|
outfile = open(str(idv) + ".json", "w")
|
|
84
105
|
outfile.write(json.dumps(metadata, indent=4))
|
|
85
106
|
outfile.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{caltechdata_api-1.8.0 → caltechdata_api-1.8.2}/caltechdata_api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|