def load_cookies(self, driver, buttons):
driver.get("https://x.com")
time.sleep(0.5)
buttons.click_element("accept_cookies", "accept cookies")
buttons.click_element("migration_btt", "migration button")
with open(os.path.join(self.paths.twitter_cookies, f"{self.account}.pkl"), 'rb') as cookies_file:
cookies = pickle.load(cookies_file)
attempt = 0
while attempt < 3:
time.sleep(0.5)
for cookie in cookies:
driver.add_cookie(cookie)
time.sleep(2)
driver.refresh()
time.sleep(2)
if self.check_cookies_loaded_succesfully(driver, buttons):
return True
else:
attempt += 1
time.sleep(2)
return False
def save_cookies(self, driver):
cookie_path = os.path.join(self.paths.twitter_cookies, f"{self.account}.pkl")
os.makedirs(os.path.dirname(cookie_path), exist_ok=True)
cookies = driver.get_cookies()
with open(cookie_path, "wb") as cookies_file:
pickle.dump(cookies, cookies_file)