Passing args to CloudScraper: attempt 2

This commit is contained in:
DarkCat09 2022-10-10 11:31:14 +04:00
parent 0e967d2755
commit 092f9356a3
2 changed files with 25 additions and 8 deletions

View file

@ -74,20 +74,22 @@ class Client:
return a valid session cookie
"""
atconn = AternosConnect()
if len(custom_args) > 0:
atconn.add_args(**custom_args)
filename = cls.session_file(
username, sessions_dir
)
try:
return cls.restore_session(filename)
return cls.restore_session(
filename, **custom_args
)
except (OSError, CredentialsError):
pass
atconn = AternosConnect()
if len(custom_args) > 0:
atconn.add_args(**custom_args)
atconn.parse_token()
atconn.generate_sec()

View file

@ -37,16 +37,31 @@ class AternosConnect:
def add_args(self, **kwargs) -> None:
"""Pass arguments to
CloudScarper session object __init__
"""Pass arguments to CloudScarper
session object __init__
if kwargs is not empty
Args:
**kwargs: Keyword arguments
"""
if len(kwargs) < 1:
logging.debug('**kwargs is empty')
return
logging.debug('New args for CloudScraper: %s', kwargs)
self.cf_init = partial(CloudScraper, **kwargs)
self.refresh_session()
def clear_args(self) -> None:
"""Clear CloudScarper object __init__ arguments
which was set using add_args method"""
logging.debug('Creating session object with no keywords')
self.cf_init = partial(CloudScraper)
self.refresh_session()
def refresh_session(self) -> None:
"""Creates a new CloudScraper