Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
updated logger and session code ..
Browse files Browse the repository at this point in the history
  • Loading branch information
r0oth3x49 committed Sep 12, 2020
1 parent 5f9e70f commit 1da8f41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions udemy/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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
)
Expand Down
16 changes: 12 additions & 4 deletions udemy/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1da8f41

Please sign in to comment.