diff --git a/udemy/extract.py b/udemy/extract.py index 829b1d0..ae4de14 100644 --- a/udemy/extract.py +++ b/udemy/extract.py @@ -81,7 +81,7 @@ def _login(self, username="", password="", cookies=""): # check if we already have session on udemy. auth = UdemyAuth() is_exists, conf = auth.is_session_exists() - if is_exists: + if is_exists and username and password: logger.info( msg="Using existing session..", new_line=True, ) @@ -107,7 +107,6 @@ def _login(self, username="", password="", cookies=""): self._cookies = extract_cookie_string(raw_cookies=cookies) self._access_token = self._cookies.get("access_token") client_id = self._cookies.get("client_id") - time.sleep(0.3) self._session, _ = auth.authenticate( access_token=self._access_token, client_id=client_id ) diff --git a/udemy/logger.py b/udemy/logger.py index e4d6215..4af1e21 100644 --- a/udemy/logger.py +++ b/udemy/logger.py @@ -60,8 +60,12 @@ class Logging(ProgressBar): Custom logging class for udemy """ + def __init__(self, log_filepath=None): + self._log_filepath = log_filepath + def set_log_filepath(self, log_filepath): file_handler = logging.FileHandler(log_filepath) + self._log_filepath = log_filepath logging.basicConfig( format="[%(asctime)s][%(name)s] %(levelname)-5.5s %(message)s", level=logging.INFO, @@ -188,7 +192,8 @@ def failed(self, msg): + Style.DIM + "] : " ) - log.error(msg) + if self._log_filepath: + log.error(msg) msg = ( set_color(f"{msg} (", level=70) + set_color("failed", level=40) @@ -212,7 +217,8 @@ def warning(self, msg): + Style.DIM + "] : " ) - log.warning(msg) + if self._log_filepath: + log.warning(msg) msg = set_color(f"{msg}\n", level=70) string = prefix + msg sys.stdout.write(string) @@ -232,7 +238,8 @@ def error(self, msg, new_line=False): + Style.DIM + "] : " ) - log.error(msg) + if self._log_filepath: + log.error(msg) if not new_line: msg = set_color(f"{msg}\n", level=40) string = prefix + msg @@ -281,7 +288,8 @@ def download_skipped(self, msg, reason=""): + Style.DIM + "] : " ) - log.warning(msg) + if self._log_filepath: + log.warning(msg) msg = ( set_color(f"{msg} (", level=70) + set_color("download skipped", level=30)