Make root API serialisable
This commit is contained in:
parent
d4fff8d61a
commit
b3a5b4acdb
@ -449,7 +449,6 @@ class FAAPI:
|
||||
"""
|
||||
self._cookies = None
|
||||
self._req = requests.session()
|
||||
self._driver = None
|
||||
self.logged_in = False
|
||||
self.username = None
|
||||
self._usercache = {}
|
||||
@ -468,16 +467,16 @@ class FAAPI:
|
||||
|
||||
if not cookies:
|
||||
# Try sign in to FA
|
||||
self._driver = webdriver.Chrome()
|
||||
self._driver.get(FA_BASE_URL + '/login')
|
||||
driver = webdriver.Chrome()
|
||||
driver.get(FA_BASE_URL + '/login')
|
||||
|
||||
# Wait until our username is visible on the top banner
|
||||
while not self._driver.find_elements_by_id('my-username'):
|
||||
while not driver.find_elements_by_id('my-username'):
|
||||
pass
|
||||
|
||||
# Extract the cookies and stop the driver
|
||||
self._cookies = self._driver.get_cookies()
|
||||
self._driver.close()
|
||||
self._cookies = driver.get_cookies()
|
||||
driver.close()
|
||||
else:
|
||||
self._cookies = cookies
|
||||
|
||||
@ -564,3 +563,17 @@ class FAAPI:
|
||||
if not submission._api:
|
||||
submission._api = self
|
||||
return submission
|
||||
|
||||
def __getstate__(self):
|
||||
# Get a copy of the object state without the requests session
|
||||
state = self.__dict__.copy()
|
||||
del(state['req'])
|
||||
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
# Set up the object with the given state
|
||||
self.__dict__.update(state)
|
||||
|
||||
# Create a new requests session
|
||||
self._req = requests.session()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user