From c7020e810a4f86b2356fae5461f9921a246dc99b Mon Sep 17 00:00:00 2001 From: Melih DARCAN <57872471+MelihDarcanxyz@users.noreply.github.com> Date: Thu, 4 Jan 2024 18:52:05 +0300 Subject: [PATCH] fix: disgenet takes creds as parameters instead of with prompt --- node_data/disgenet_local.py | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/node_data/disgenet_local.py b/node_data/disgenet_local.py index 38b0e92..285b378 100644 --- a/node_data/disgenet_local.py +++ b/node_data/disgenet_local.py @@ -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 @@ -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. @@ -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} @@ -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): """ @@ -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]]