Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disgenet takes creds as parameters instead of with prompt #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions node_data/disgenet_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import pypath.share.curl as curl
import pypath.share.session as session
import pypath.resources.urls as urls
import pypath.utils.mapping as mapping

_logger = session.Logger(name="disgenet_input")
_log = _logger._log
Expand All @@ -45,7 +44,11 @@ class DisgenetApi:
_authenticated: bool = False
_api_key: str = None

def authenticate(self) -> bool:
def __init__(self, e_mail, password):

self.authenticate(e_mail, password)

def authenticate(self, e_mail, password) -> bool:
"""
Starts an authorization process in DisGeNET API.
Returns a boolean which is success of authentication.
Expand All @@ -55,8 +58,6 @@ def authenticate(self) -> bool:
return True

print(f"Authorizing in {self._name} API...")
e_mail: str = input("E-mail: ")
password: str = getpass("Password: ")

url: str = f"{self._api_url}/auth/"
post_params: dict[str, str] = {"email": e_mail, "password": password}
Expand All @@ -78,23 +79,7 @@ def authenticate(self) -> bool:
self._authenticated = False
self._api_key = None

return self._authenticated and (self._api_key != None)

def _if_authenticated(f):
"""
Simple wrapper to get rid of the burden of
checking authentication status and authenticating
if already haven't.
"""

def wrapper(self, *args, **kwargs):
if self.authenticate():
return f(self, *args, **kwargs)

else:
print("Failure in authorization, check your credentials.")

return wrapper
assert self._authenticated and (self._api_key != None)

def _delete_cache(f):
"""
Expand Down Expand Up @@ -1972,7 +1957,7 @@ def _list_to_str(

return list_obj

@_if_authenticated
# @_if_authenticated
@_delete_cache
def _retrieve_data(
self, url: str, get_params: Union[List[str], Dict[str, str]]
Expand Down