Skip to content

Commit 60a827e

Browse files
committed
Fix validation on context of cli
1 parent 1c14752 commit 60a827e

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

caltechdata_api/cli.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import requests
33
import s3fs
4+
from datetime import datetime
45
from caltechdata_api import caltechdata_write, caltechdata_edit
56
from .md_to_json import parse_readme_to_json
67
import json
@@ -140,7 +141,7 @@ def get_funding_entries():
140141
def validate_funder_identifier(funder_identifier):
141142
response = requests.get(f"https://api.ror.org/organizations/{funder_identifier}")
142143
if response.status_code == 200:
143-
return True
144+
return response.json().get("name")
144145
else:
145146
return False
146147

@@ -157,7 +158,8 @@ def get_funding_details():
157158
award_title = get_user_input("Enter the award title for funding: ")
158159
while True:
159160
funder_identifier = get_user_input("Enter the funder ROR (https://ror.org): ")
160-
if validate_funder_identifier(funder_identifier):
161+
name = validate_funder_identifier(funder_identifier)
162+
if name:
161163
break
162164
else:
163165
print(
@@ -169,6 +171,7 @@ def get_funding_details():
169171
return {
170172
"awardNumber": award_number,
171173
"awardTitle": award_title,
174+
"funderName": name,
172175
"funderIdentifier": funder_identifier,
173176
"funderIdentifierType": "ROR",
174177
}
@@ -194,9 +197,18 @@ def parse_arguments():
194197
if license_number.isdigit() and 1 <= int(license_number) <= 8:
195198
# Valid license number selected
196199
args["license"] = {
197-
"1": "cc0-1.0",
198-
"2": "cc-by-4.0",
199-
"3": "cc-by-nc-4.0",
200+
"1": {
201+
"rights": "Creative Commons Zero v1.0 Universal",
202+
"rightsIdentifier": "cc0-1.0",
203+
},
204+
"2": {
205+
"rights": "Creative Commons Attribution v4.0 Universal",
206+
"rightsIdentifier": "cc-by-4.0",
207+
},
208+
"3": {
209+
"rights": "Creative Commons Attribution Non-Commercial v4.0 Universal",
210+
"rightsIdentifier": "cc-by-nc-4.0",
211+
},
200212
}[license_number]
201213
break
202214
else:
@@ -259,9 +271,11 @@ def get_names(orcid):
259271
return family_name, given_name
260272

261273

262-
def write_s3cmd_config(access_key, secret_key, endpoint):
274+
def write_s3cmd_config(endpoint):
263275
configf = os.path.join(home_directory, ".s3cfg")
264276
if not os.path.exists(configf):
277+
access_key = get_user_input("Enter the access key: ")
278+
secret_key = get_user_input("Enter the secret key: ")
265279
with open(configf, "w") as file:
266280
file.write(
267281
f"""[default]
@@ -286,9 +300,7 @@ def upload_supporting_file(record_id=None):
286300
endpoint = "sdsc.osn.xsede.org"
287301
path = "ini230004-bucket01/"
288302
if not record_id:
289-
access_key = get_user_input("Enter the access key: ")
290-
secret_key = get_user_input("Enter the secret key: ")
291-
write_s3cmd_config(access_key, secret_key, endpoint)
303+
write_s3cmd_config(endpoint)
292304
print("""S3 connection configured.""")
293305
break
294306
endpoint = f"https://{endpoint}/"
@@ -450,6 +462,7 @@ def create_record(production):
450462
elif choice == "create":
451463
args = parse_arguments()
452464
family_name, given_name = get_names(args["orcid"])
465+
today = datetime.today().date().isoformat()
453466
metadata = {
454467
"titles": [{"title": args["title"]}],
455468
"descriptions": [
@@ -478,9 +491,7 @@ def create_record(production):
478491
],
479492
"types": {"resourceType": "", "resourceTypeGeneral": "Dataset"},
480493
"rightsList": [
481-
{
482-
"rightsIdentifier": args["license"],
483-
}
494+
args["license"],
484495
],
485496
"fundingReferences": args["fundingReferences"],
486497
"schemaVersion": "http://datacite.org/schema/kernel-4",

caltechdata_api/customize_schema.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,7 @@ def validate_metadata(json_record):
415415
"Each entry in 'titles' must be a dictionary with a 'title' key."
416416
)
417417

418-
# Check for 'publication_date'
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-
)
418+
# Publication date is handled by customize function
436419

437420
# Check for 'creators'
438421
if "creators" not in json_record:

0 commit comments

Comments
 (0)