Move login logic out of __init__
This commit is contained in:
parent
aaf7445b8f
commit
c0ed667f18
@ -421,16 +421,27 @@ class FAAPI:
|
|||||||
A basic FurAffinity API instance.
|
A basic FurAffinity API instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, use_webdriver: bool = True):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialises a new FAAPI instance.
|
Initialises a new FAAPI instance.
|
||||||
Beware that a Chrome instance is launched to bypass Cloudflare and log in during initialisation. Change use_webdriver to False to disable this.
|
|
||||||
"""
|
"""
|
||||||
|
self._cookies = None
|
||||||
|
self._req = None
|
||||||
|
self._driver = None
|
||||||
|
self.logged_in = False
|
||||||
|
self.username = None
|
||||||
|
|
||||||
if not use_webdriver:
|
def login(self, cookies=None) -> None:
|
||||||
# Can't do any actual API things, stop here
|
"""
|
||||||
|
Logs this instance into FurAffinity.
|
||||||
|
Beware that a Chrome instance is launched to bypass Cloudflare and log in. Specify valid cookies to bypass this.
|
||||||
|
@param cookies: Cookies to use for this session.
|
||||||
|
"""
|
||||||
|
if self.logged_in:
|
||||||
|
# No need to do anything if we're already logged in
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not cookies:
|
||||||
# Try sign in to FA
|
# Try sign in to FA
|
||||||
self._driver = webdriver.Chrome()
|
self._driver = webdriver.Chrome()
|
||||||
self._driver.get(FA_BASE_URL + '/login')
|
self._driver.get(FA_BASE_URL + '/login')
|
||||||
@ -445,6 +456,8 @@ class FAAPI:
|
|||||||
# Extract the cookies and stop the driver
|
# Extract the cookies and stop the driver
|
||||||
self._cookies = self._driver.get_cookies()
|
self._cookies = self._driver.get_cookies()
|
||||||
self._driver.close()
|
self._driver.close()
|
||||||
|
else:
|
||||||
|
self._cookies = cookies
|
||||||
|
|
||||||
# Set up a Requests session with the cookies we just got
|
# Set up a Requests session with the cookies we just got
|
||||||
self._req = requests.session()
|
self._req = requests.session()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user