Skip to content

Commit 21e7cd7

Browse files
committed
Update message formatting
1 parent 27a5070 commit 21e7cd7

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

caltechdata_api/cli.py

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -375,22 +375,22 @@ def upload_data_from_file():
375375
except json.JSONDecodeError as e:
376376
print(f"Error: Invalid JSON format in the file '{filename}'. {str(e)}")
377377

378+
378379
def parse_args():
379380
"""Parse command-line arguments."""
380381
parser = argparse.ArgumentParser(description="CaltechDATA CLI tool.")
381382
parser.add_argument(
382-
"-test",
383-
action="store_true",
384-
help="Use test mode, sets production to False"
383+
"-test", action="store_true", help="Use test mode, sets production to False"
385384
)
386385
args = parser.parse_args()
387386
return args
388387

388+
389389
def main():
390390
args = parse_args()
391-
391+
392392
production = not args.test # Set production to False if -test flag is provided
393-
393+
394394
choice = get_user_input(
395395
"Do you want to create or edit a CaltechDATA record? (create/edit): "
396396
).lower()
@@ -415,7 +415,11 @@ def create_record(production):
415415
if existing_data:
416416
if filepath != "":
417417
response = caltechdata_write(
418-
existing_data, token, filepath, production=production, publish=False
418+
existing_data,
419+
token,
420+
filepath,
421+
production=production,
422+
publish=False,
419423
)
420424
elif file_link != "":
421425
response = caltechdata_write(
@@ -492,7 +496,6 @@ def create_record(production):
492496
metadata, token, production=production, publish=False
493497
)
494498
rec_id = response
495-
496499

497500
print_upload_message(rec_id, production)
498501
with open(response + ".json", "w") as file:
@@ -503,20 +506,29 @@ def create_record(production):
503506
else:
504507
print("Invalid choice. Please enter 'existing' or 'create'.")
505508

509+
506510
def print_upload_message(rec_id, production):
507-
base_url = "https://data.caltech.edu/uploads/" if production else "https://data.caltechlibrary.dev/uploads/"
511+
base_url = (
512+
"https://data.caltech.edu/uploads/"
513+
if production
514+
else "https://data.caltechlibrary.dev/uploads/"
515+
)
508516
print(
509-
f"""You can view and publish this record at
517+
f"""
518+
You can view and publish this record at
519+
510520
{base_url}{rec_id}
511-
If you need to upload large files to S3, you can type
512-
`s3cmd put DATA_FILE s3://ini230004-bucket01/{rec_id}/`"""
521+
522+
If you need to upload large files to S3, you can type `s3cmd put DATA_FILE s3://ini230004-bucket01/{rec_id}/`
523+
"""
513524
)
514525

526+
515527
def edit_record(production):
516528
record_id = input("Enter the CaltechDATA record ID: ")
517529
token = get_or_set_token()
518530
file_name = download_file_by_id(record_id, token)
519-
531+
520532
if file_name:
521533
try:
522534
# Read the edited metadata file
@@ -533,30 +545,38 @@ def edit_record(production):
533545
print(f"An error occurred during metadata editing: {e}")
534546
else:
535547
print("No metadata file found.")
536-
548+
537549
choice = get_user_input("Do you want to add files? (y/n): ").lower()
538550
if choice == "y":
539551
if production:
540552
API_URL_TEMPLATE = "https://data.caltech.edu/api/records/{record_id}/files"
541-
API_URL_TEMPLATE_DRAFT = "https://data.caltech.edu/api/records/{record_id}/draft/files"
553+
API_URL_TEMPLATE_DRAFT = (
554+
"https://data.caltech.edu/api/records/{record_id}/draft/files"
555+
)
542556
else:
543-
API_URL_TEMPLATE = "https://data.caltechlibrary.dev/api/records/{record_id}/files"
544-
API_URL_TEMPLATE_DRAFT = "https://data.caltechlibrary.dev/api/records/{record_id}/draft/files"
545-
557+
API_URL_TEMPLATE = (
558+
"https://data.caltechlibrary.dev/api/records/{record_id}/files"
559+
)
560+
API_URL_TEMPLATE_DRAFT = (
561+
"https://data.caltechlibrary.dev/api/records/{record_id}/draft/files"
562+
)
563+
546564
url = API_URL_TEMPLATE.format(record_id=record_id)
547565
url_draft = API_URL_TEMPLATE_DRAFT.format(record_id=record_id)
548-
566+
549567
response = requests.get(url)
550568
response_draft = requests.get(url_draft)
551-
569+
552570
filepath, file_link = upload_supporting_file(record_id)
553571
print(file_link)
554-
572+
555573
if response.status_code == 404 and response_draft.status_code == 404:
556574
keepfile = False
557575
else:
558-
keepfile = input("Do you want to keep existing files? (y/n): ").lower() == "y"
559-
576+
keepfile = (
577+
input("Do you want to keep existing files? (y/n): ").lower() == "y"
578+
)
579+
560580
if filepath != "":
561581
response = caltechdata_edit(
562582
record_id,
@@ -576,12 +596,9 @@ def edit_record(production):
576596
publish=False,
577597
keepfile=keepfile,
578598
)
579-
599+
580600
rec_id = response
581601
print_upload_message(rec_id, production)
582-
583-
584-
585602

586603

587604
def download_file_by_id(record_id, token=None):

0 commit comments

Comments
 (0)