Skip to content

Commit d94ac45

Browse files
Update cli.py
1 parent 4cfee65 commit d94ac45

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

caltechdata_api/cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def save_profile():
204204
# Get ORCID
205205
while True:
206206
orcid = get_user_input("Enter your ORCID identifier: ")
207+
orcid = normalize_orcid(orcid)
207208
family_name, given_name = get_names(orcid)
208209
if family_name is not None and given_name is not None:
209210
break
@@ -476,6 +477,19 @@ def parse_args():
476477
return args
477478

478479

480+
def normalize_orcid(val):
481+
orcid_urls = ["https://orcid.org/", "http://orcid.org/", "orcid.org/"]
482+
for orcid_url in orcid_urls:
483+
if val.startswith(orcid_url):
484+
val = val[len(orcid_url) :]
485+
break
486+
487+
val = val.replace("-", "").replace(" ", "")
488+
if len(val) != 16 or not val.isdigit():
489+
raise ValueError(f"Invalid ORCID identifier: {val}")
490+
return "-".join([val[0:4], val[4:8], val[8:12], val[12:16]])
491+
492+
479493
def main():
480494
args = parse_args()
481495
production = not args.test

0 commit comments

Comments
 (0)