Skip to content

Commit

Permalink
refactor: Unite orcid list & single orcid function
Browse files Browse the repository at this point in the history
- Instead of repeating code between import info from list and import
  info, include a type guard on import_info to check if the argument
provided is a path or a just a string.

- Addresses lubianat#14
  • Loading branch information
jvfe committed Apr 10, 2022
1 parent 52550f2 commit 40126eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/pyorcidator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def cli():


cli.add_command(import_info.main)
cli.add_command(import_info_from_list.main)

if __name__ == "__main__":
cli()
26 changes: 21 additions & 5 deletions src/pyorcidator/import_info.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
from .helper import *
from urllib.parse import quote
import click
from pathlib import Path


@click.command(name="import")
@click.option("--orcid", prompt=True, help="The ORCID Id to look up")
def main(orcid: str):
qs = render_orcid_qs(orcid)
@click.option(
"--orcids",
prompt="ORCID ID or a path to list of ORCID IDs",
help=(
"The ORCID ID to look up or a Path to"
"a txt file containing one ORCID per line"
),
)
def main(orcids: str):
if Path(orcids).is_file():
p = Path(orcids)
list_of_orcids = p.read_text().split("\n")
qs = ""
for orcid in list_of_orcids:
qs = qs + render_orcid_qs(orcid)
else:
qs = render_orcid_qs(orcids)

quoted_qs = quote(qs.replace("\t", "|").replace("\n", "||"), safe="")
url = f"https://quickstatements.toolforge.org/#/v1={quoted_qs}\\"
print(qs)
print(url)
click.echo(qs)
click.echo(url)


if __name__ == "__main__":
Expand Down
27 changes: 0 additions & 27 deletions src/pyorcidator/import_info_from_list.py

This file was deleted.

0 comments on commit 40126eb

Please sign in to comment.