-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDIT: make examples consisten with the latest package update + improv…
…e code quality
- Loading branch information
1 parent
dd5b2fc
commit 4f47d0c
Showing
17 changed files
with
328 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
dist/* | ||
orcidpyclient.egg-info/* | ||
docs/_build/* | ||
generated/* | ||
|
||
# extensions | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# importing module located in parent folder | ||
import sys | ||
|
||
sys.path.insert(0, "../") | ||
|
||
import sys | ||
import pyorcid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
__all__ = ('get', 'search', 'orcid_api_version') | ||
__all__ = ("get", "search", "orcid_api_version") | ||
|
||
from .rest import get, search, orcid_api_version | ||
from .functions import get, orcid_api_version, search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ORCID_API_VERSION = '3.0' | ||
ORCID_PUBLIC_BASE_URL = f'https://pub.orcid.org/v{ORCID_API_VERSION}/' | ||
ORCID_SANDBOX_BASE_URL = 'https://pub.orcid.org/' | ||
ORCID_API_VERSION = "3.0" | ||
ORCID_PUBLIC_BASE_URL = f"https://pub.orcid.org/v{ORCID_API_VERSION}/" | ||
ORCID_SANDBOX_BASE_URL = "https://pub.orcid.org/" | ||
|
||
BASE_HEADERS = {"Accept": "application/orcid+json", "Content-Type": "application/json;charset=UTF-8"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class ORCIDException(Exception): | ||
pass | ||
|
||
|
||
class NotFoundException(ORCIDException): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import json | ||
import logging | ||
import sys | ||
|
||
import requests | ||
|
||
from .constants import BASE_HEADERS, ORCID_API_VERSION, ORCID_PUBLIC_BASE_URL | ||
from .logger_config import logger, stdout_sh | ||
from .rest import Author | ||
|
||
|
||
def _set_logger_debug(debug: bool = False): | ||
"""_summary_ | ||
Args: | ||
debug (bool, optional): _description_. Defaults to False. | ||
""" | ||
|
||
if debug: | ||
logger.setLevel(logging.DEBUG) | ||
stdout_sh.setLevel(logging.DEBUG) | ||
|
||
|
||
def get(orcid_id: str, debug: bool = False): | ||
"""Get an author based on an ORCID identifier.""" | ||
|
||
_set_logger_debug(debug) | ||
|
||
if sys.version_info[0] < 3: | ||
raise Exception("Python 2 is not supported") | ||
|
||
_url = f"{ORCID_PUBLIC_BASE_URL}{orcid_id}" | ||
_res = requests.get(_url, headers=BASE_HEADERS) | ||
|
||
json_body = _res.json() | ||
|
||
logger.debug("RESPONSE (BASE): {0}".format(json.dumps(json_body, sort_keys=True, indent=4, separators=(",", ": ")))) | ||
|
||
return Author(json_body) | ||
|
||
|
||
def search(query, debug: bool = False): | ||
"""Search the ORCID by sending a query to API | ||
API documentation: | ||
https://info.orcid.org/documentation/api-tutorials/api-tutorial-searching-the-orcid-registry/ | ||
api_example_query = {'q':'family-name:Malavolti+AND+given-names:Marco'} | ||
Args: | ||
query (_type_): query string | ||
debug (bool, optional): option for the logging. Defaults to False. | ||
Returns: | ||
_type_: iterator of the results | ||
""" | ||
|
||
_set_logger_debug(debug) | ||
|
||
if sys.version_info[0] < 3: | ||
raise Exception("Python 2 is not supported") | ||
|
||
_url = f"{ORCID_PUBLIC_BASE_URL}search?q={query}" | ||
resp = requests.get(_url, headers=BASE_HEADERS) | ||
logger.debug(resp.url) | ||
json_body = resp.json() | ||
logger.debug(json_body) | ||
if json_body.get("result") is not None: | ||
return (get(res.get("orcid-identifier", {}).get("path")) for res in json_body.get("result", {})) | ||
else: | ||
return iter(list()) | ||
|
||
|
||
def orcid_api_version(): | ||
"""Provides version of ORCID API that is used""" | ||
return ORCID_API_VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import logging | ||
import sys | ||
|
||
_logger_depth = "INFO" | ||
|
||
logger = logging.getLogger("#orcid#") | ||
logger.setLevel(getattr(logging, _logger_depth)) | ||
|
||
stdout_sh = logging.StreamHandler(sys.stdout) | ||
stdout_sh.setLevel(getattr(logging, _logger_depth)) | ||
stdout_sh.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) | ||
|
||
logger.addHandler(stdout_sh) |
Oops, something went wrong.