Skip to content

Commit eb4b90a

Browse files
committed
Black formatting
1 parent 4fdaa54 commit eb4b90a

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

caltechdata_api/cli.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ def create_record():
360360
existing_data, token, production=False, publish=False
361361
)
362362
rec_id = response
363-
print(f'You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}')
363+
print(
364+
f"You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}"
365+
)
364366
break
365367
else:
366368
print("Going back to the main menu.")
@@ -421,7 +423,9 @@ def create_record():
421423
metadata, token, production=False, publish=False
422424
)
423425
rec_id = response
424-
print(f'You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}')
426+
print(
427+
f"You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}"
428+
)
425429
with open(response + ".json", "w") as file:
426430
json.dump(metadata, file, indent=2)
427431
break
@@ -434,15 +438,15 @@ def create_record():
434438
def edit_record():
435439
record_id = input("Enter the CaltechDATA record ID: ")
436440
token = get_or_set_token()
437-
file_name = download_file_by_id(record_id,token)
441+
file_name = download_file_by_id(record_id, token)
438442
if file_name:
439443
try:
440444
# Read the edited metadata file
441445
with open(file_name, "r") as file:
442446
metadata = json.load(file)
443447
response = caltechdata_edit(
444-
record_id, metadata, token, production=False, publish=False
445-
)
448+
record_id, metadata, token, production=False, publish=False
449+
)
446450
if response:
447451
print("Metadata edited successfully.")
448452
else:
@@ -469,12 +473,14 @@ def edit_record():
469473
publish=False,
470474
)
471475
rec_id = response
472-
print(f'You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}')
476+
print(
477+
f"You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}"
478+
)
473479

474480

475-
def download_file_by_id(record_id,token=None):
481+
def download_file_by_id(record_id, token=None):
476482
url = f"https://data.caltechlibrary.dev/api/records/{record_id}"
477-
483+
478484
headers = {
479485
"accept": "application/vnd.datacite.datacite+json",
480486
}
@@ -483,12 +489,12 @@ def download_file_by_id(record_id,token=None):
483489
headers["Authorization"] = "Bearer %s" % token
484490

485491
try:
486-
response = requests.get(url,headers=headers)
492+
response = requests.get(url, headers=headers)
487493
if response.status_code != 200:
488494
# Might have a draft
489495
response = requests.get(
490-
url + "/draft",
491-
headers=headers,
496+
url + "/draft",
497+
headers=headers,
492498
)
493499
if response.status_code != 200:
494500
raise Exception(f"Record {record_id} does not exist, cannot edit")

caltechdata_api/md_to_json.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ def camel_case(s):
1616
def expand_special_keys(key, value):
1717
"""Expand special keys into their structured format (affiliation, nameIdentifiers)."""
1818
if key == "affiliation":
19-
if 'ror.org' not in value:
20-
raise ValueError('Affiliation Identifier is not a ROR')
21-
ror = value.split('ror.org/')[1].split(']')[0]
22-
response = requests.get(f'https://api.ror.org/organizations/{ror}').json()
23-
return [{"affiliationIdentifier": ror, "affiliationIdentifierScheme": "ROR","name":response['name']}]
19+
if "ror.org" not in value:
20+
raise ValueError("Affiliation Identifier is not a ROR")
21+
ror = value.split("ror.org/")[1].split("]")[0]
22+
response = requests.get(f"https://api.ror.org/organizations/{ror}").json()
23+
return [
24+
{
25+
"affiliationIdentifier": ror,
26+
"affiliationIdentifierScheme": "ROR",
27+
"name": response["name"],
28+
}
29+
]
2430
elif key == "nameIdentifiers":
25-
orcid = value.split('orcid.org/')[1].split(']')[0]
31+
orcid = value.split("orcid.org/")[1].split("]")[0]
2632
return [
2733
{
2834
"nameIdentifier": orcid,
@@ -44,10 +50,10 @@ def parse_readme_to_json(readme_path):
4450
current_object = {}
4551

4652
title_line = lines.pop(0)
47-
if title_line.startswith('#') == False:
53+
if title_line.startswith("#") == False:
4854
raise ValueError('README.md needs to start with "# Title"')
4955
else:
50-
json_data['titles'] = [{'title':title_line.replace("# ","")}]
56+
json_data["titles"] = [{"title": title_line.replace("# ", "")}]
5157

5258
section_pattern = re.compile(r"^##\s+(.*)$")
5359
key_value_pattern = re.compile(r"^-\s+(.*?):\s+(.*)$")
@@ -61,7 +67,7 @@ def parse_readme_to_json(readme_path):
6167
elif len(current_object) == 1:
6268
key, value = next(iter(current_object.items()))
6369
if key in ["language", "publicationYear", "publisher", "version"]:
64-
json_data[current_section]=value
70+
json_data[current_section] = value
6571
else:
6672
json_data[current_section].append(current_object)
6773
else:
@@ -120,7 +126,8 @@ def parse_readme_to_json(readme_path):
120126

121127
return json_data
122128

123-
if __name__ == '__main__':
129+
130+
if __name__ == "__main__":
124131
readme_path = "exampleREADME.md"
125132
try:
126133
json_data = parse_readme_to_json(readme_path)

process_tomograms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Set OpenAI API key from environment variable
1212
openai.api_key = os.getenv("OPENAI_API_KEY")
1313

14+
1415
# Function to parse collaborators using OpenAI API
1516
def parse_collaborators(collaborator_string):
1617
# Using OpenAI API to extract names and contributions
@@ -55,6 +56,7 @@ def parse_collaborators(collaborator_string):
5556
formatted.append(new)
5657
return formatted
5758

59+
5860
# Function to create a description based on the metadata
5961
def create_detailed_description(information, annotation):
6062
keywords = []
@@ -142,6 +144,7 @@ def create_detailed_description(information, annotation):
142144
)
143145
return description, keywords
144146

147+
145148
# Function for processing files and extracting information
146149
def process_files(files, embargoed):
147150
formats = []
@@ -206,6 +209,7 @@ def process_files(files, embargoed):
206209
default_preview,
207210
)
208211

212+
209213
# List of funding resources
210214
funding = [
211215
{"funderName": "NIH"},
@@ -228,6 +232,7 @@ def process_files(files, embargoed):
228232
},
229233
]
230234

235+
231236
# Function for processing a single tomogram record
232237
def process_record(source, edit=None):
233238
# Extract information from the record
@@ -414,6 +419,7 @@ def process_record(source, edit=None):
414419
except FileNotFoundError:
415420
print("Not deleting remaned files")
416421

422+
417423
# Read record IDs from a file
418424
with open("tomogram_ids.json", "r") as infile:
419425
record_ids = json.load(infile)

setup.py

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

7373
# What packages are optional?

0 commit comments

Comments
 (0)