From b3a5b4acdb601e2433f1429cee5474c348d40cd6 Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Wed, 22 Apr 2020 16:29:06 +0930 Subject: [PATCH] Make root API serialisable --- FAAPI/FAAPI.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/FAAPI/FAAPI.py b/FAAPI/FAAPI.py index 938cb9e..3bbcda0 100644 --- a/FAAPI/FAAPI.py +++ b/FAAPI/FAAPI.py @@ -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()