def is_session_exists(self): is_exists = False conf = load_configs() if conf: cookies = conf.get("cookies") if cookies: cookies = extract_cookie_string(cookies) access_token = cookies.get("access_token") client_id = cookies.get("client_id") self._session._set_auth_headers( # pylint: disable=W access_token=access_token, client_id=client_id) self._session._session.cookies.update( # pylint: disable=W {"access_token": access_token}) try: url = "https://www.udemy.com/api-2.0/courses/" resp = self._session._get(url) # pylint: disable=W resp.raise_for_status() is_exists = True except Exception as error: # pylint: disable=W logger.error( msg= f"Udemy Says: {error} session cookie seems to be expired..." ) is_exists = False return is_exists, conf
def _login(self, username="", password="", cookies="", cache_session=False): # check if we already have session on udemy. auth = UdemyAuth(cache_session=cache_session) is_exists, conf = auth.is_session_exists() if is_exists and username and password: logger.info( msg="Using existing session..", new_line=True, ) cookies = conf.get("cookies") if not is_exists and not cookies: cookies = None if not username and not password: logger.info( msg="Updating session cookie..", new_line=True, ) username = conf.get("username") password = conf.get("password") if not username and not password and not cookies: print("") cookies = getpass.get_access_token(prompt="Access Token : ") if not cookies: username = getpass.getuser(prompt="Username : "******"Password : "******"\n") if not cookies and not username and not password: logger.error( msg= f"You should either provide Fresh Access Token or Username/Password to create new udemy session.." ) sys.exit(0) if not cookies: auth.username = username auth.password = password self._session, self._access_token = auth.authenticate() if cookies: self._cookies = extract_cookie_string(raw_cookies=cookies) self._access_token = self._cookies.get("access_token") client_id = self._cookies.get("client_id") self._session, _ = auth.authenticate( access_token=self._access_token, client_id=client_id) self._session._session.cookies.update(self._cookies) if self._session is not None: return {"login": "******"} else: return {"login": "******"}
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 and username and password: logger.info( msg="Using existing session..", new_line=True, ) cookies = conf.get("cookies") if not is_exists: cookies = None if not username and not password: logger.info( msg="Updating session cookie..", new_line=True, ) username = conf.get("username") password = conf.get("password") if not username and not password: print("") username = getpass.getuser(prompt="Username : "******"Password : "******"\n") if not cookies: auth.username = username auth.password = password self._session, self._access_token = auth.authenticate() if cookies: self._cookies = extract_cookie_string(raw_cookies=cookies) self._access_token = self._cookies.get("access_token") client_id = self._cookies.get("client_id") self._session, _ = auth.authenticate( access_token=self._access_token, client_id=client_id) self._session._session.cookies.update(self._cookies) if self._session is not None: return {"login": "******"} else: return {"login": "******"}