diff --git a/src/py4lexis/session.py b/src/py4lexis/session.py index f13f3ab..06188f1 100644 --- a/src/py4lexis/session.py +++ b/src/py4lexis/session.py @@ -10,12 +10,15 @@ from urllib3 import disable_warnings from time import perf_counter import json +import os disable_warnings() class LexisSession(object): + ENV_VARS = {"user":"LEXIS_USERNAME", "pwd":"LEXIS_PASSWORD"} # env variables for authentication. Use a dict more for documentation reasons + def __init__(self, show_prints: Optional[bool] = True, exception_on_error: Optional[bool] = False, @@ -111,10 +114,13 @@ def _set_tokens(self) -> None: """ is_error: bool = False try: - print(f"Welcome to the Py4Lexis!") - print(f"Please provide your credentials...") - self.USERNAME: str = input("Username: ") - pwd: str = getpass() + self.USERNAME = os.environ.get(self.ENV_VARS["user"]) + pwd: str = os.environ.get(self.ENV_VARS["pwd"]) + if self.USERNAME is None or pwd is None: + print(f"Welcome to the Py4Lexis!") + print(f"Please provide your credentials...") + self.USERNAME: str = input("Username: ") + pwd: str = getpass() token: dict | dict[str, str] = self.uc.token(self.USERNAME, pwd) self.REFRESH_TOKEN = token["refresh_token"]