Skip to content

Commit 4fdaa54

Browse files
committed
Full workflow and release
1 parent 1eec824 commit 4fdaa54

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

caltechdata_api/cli.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,16 @@ def create_record():
433433

434434
def edit_record():
435435
record_id = input("Enter the CaltechDATA record ID: ")
436-
file_name = download_file_by_id(record_id)
436+
token = get_or_set_token()
437+
file_name = download_file_by_id(record_id,token)
437438
if file_name:
438439
try:
439440
# Read the edited metadata file
440441
with open(file_name, "r") as file:
441442
metadata = json.load(file)
442-
token = get_or_set_token()
443443
response = caltechdata_edit(
444-
record_id, metadata, token, production=False, publish=False
445-
)
444+
record_id, metadata, token, production=False, publish=False
445+
)
446446
if response:
447447
print("Metadata edited successfully.")
448448
else:
@@ -454,48 +454,51 @@ def edit_record():
454454
choice = get_user_input("Do you want to add files? (y/n): ").lower()
455455
if choice == "y":
456456
filepath, file_link = upload_supporting_file(record_id)
457+
print(file_link)
457458
if filepath != "":
458459
response = caltechdata_edit(
459-
record_id, metadata, token, filepath, production=False, publish=False
460+
record_id, token=token, files=filepath, production=False, publish=False
460461
)
461462
elif file_link != "":
462463
response = caltechdata_edit(
463464
record_id,
464465
metadata,
465-
token,
466+
token=token,
466467
file_links=file_link,
467468
production=False,
468469
publish=False,
469470
)
470-
else:
471-
response = caltechdata_edit(
472-
record_id, metadata, token, production=False, publish=False
473-
)
474-
rec_id = response
475-
print(f'You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}')
476-
elif choice == "n":
477-
response = caltechdata_edit(
478-
record_id, metadata, token, production=False, publish=False
479-
)
480471
rec_id = response
481472
print(f'You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}')
482-
else:
483-
print("Invalid choice. Please enter 'metadata' or 'files'.")
484473

485474

486-
def download_file_by_id(record_id):
487-
url = f"https://data.caltechlibrary.dev/records/{record_id}/export/datacite-json"
475+
def download_file_by_id(record_id,token=None):
476+
url = f"https://data.caltechlibrary.dev/api/records/{record_id}"
477+
478+
headers = {
479+
"accept": "application/vnd.datacite.datacite+json",
480+
}
481+
482+
if token:
483+
headers["Authorization"] = "Bearer %s" % token
488484

489485
try:
490-
response = requests.get(url)
491-
if response.status_code == 200:
492-
file_content = response.content
493-
file_name = f"downloaded_data_{record_id}.json"
494-
with open(file_name, "wb") as file:
495-
file.write(file_content)
496-
print(f"Metadata downloaded successfully: {file_name}")
497-
with open(file_name, "r") as file:
498-
metadata = json.load(file)
486+
response = requests.get(url,headers=headers)
487+
if response.status_code != 200:
488+
# Might have a draft
489+
response = requests.get(
490+
url + "/draft",
491+
headers=headers,
492+
)
493+
if response.status_code != 200:
494+
raise Exception(f"Record {record_id} does not exist, cannot edit")
495+
file_content = response.content
496+
file_name = f"downloaded_data_{record_id}.json"
497+
with open(file_name, "wb") as file:
498+
file.write(file_content)
499+
print(f"Metadata downloaded successfully: {file_name}")
500+
with open(file_name, "r") as file:
501+
metadata = json.load(file)
499502
while True:
500503
print("Fields:")
501504
for i, field in enumerate(metadata.keys()):
@@ -590,8 +593,6 @@ def download_file_by_id(record_id):
590593

591594
print(f"File updated successfully.")
592595

593-
else:
594-
print(f"Failed to download file. Status code: {response.status_code}")
595596
except Exception as e:
596597
print(f"An error occurred: {e}")
597598
return file_name

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"codeRepository": "https://github.com/caltechlibrary/caltechdata_api",
77
"issueTracker": "https://github.com/caltechlibrary/caltechdata_api/issues",
88
"license": "https://data.caltech.edu/license",
9-
"version": "1.5.1",
9+
"version": "1.6.0",
1010
"author": [
1111
{
1212
"@type": "Person",

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def package_files(package, directory):
6767
"pyyaml",
6868
"s3fs",
6969
"configparser",
70+
"awscli"
7071
]
7172

7273
# What packages are optional?

0 commit comments

Comments
 (0)