|
@ -1,6 +1,6 @@ |
|
|
from .archive import archiver |
|
|
from .archive import archiver |
|
|
from ..types import Conversation |
|
|
from ..types import Conversation |
|
|
from .common import SELENIUM_EXCEPTIONS, logger, click_button |
|
|
from .common import SELENIUM_EXCEPTIONS, logger, scroll_to |
|
|
from selenium.webdriver.common.by import By |
|
|
from selenium.webdriver.common.by import By |
|
|
from selenium.webdriver.support import expected_conditions as EC |
|
|
from selenium.webdriver.support import expected_conditions as EC |
|
|
from selenium.webdriver.support.ui import WebDriverWait |
|
|
from selenium.webdriver.support.ui import WebDriverWait |
|
@ -8,18 +8,44 @@ from selenium.webdriver.common.action_chains import ActionChains |
|
|
|
|
|
|
|
|
LOG = logger(__name__) |
|
|
LOG = logger(__name__) |
|
|
|
|
|
|
|
|
def get_conversation_list(driver): |
|
|
def get_conversation_list(driver, offset=0): |
|
|
""" |
|
|
""" |
|
|
Get a list of conversations |
|
|
Get a list of conversations |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
actions = ActionChains(driver) |
|
|
actions = ActionChains(driver) |
|
|
|
|
|
|
|
|
convos = driver.find_elements_by_xpath("//ul[@aria-label=\"Conversation list\"]/li") |
|
|
convos = driver.find_elements_by_xpath("//ul[@aria-label=\"Conversation list\"]/li/div/a[@role=\"link\"]") |
|
|
|
|
|
|
|
|
for convo in convos: |
|
|
for convo in convos[offset:]: |
|
|
actions.move_to_element(convo).perform() |
|
|
actions.move_to_element(convo).perform() |
|
|
yield convo.find_element_by_xpath("//a") |
|
|
yield convo |
|
|
|
|
|
actions.move_to_element(current_convo).perform() |
|
|
|
|
|
|
|
|
|
|
|
def get_all_conversations(driver): |
|
|
|
|
|
conversation_urls = set() |
|
|
|
|
|
|
|
|
|
|
|
current_convo = None |
|
|
|
|
|
|
|
|
|
|
|
while True: |
|
|
|
|
|
l = len(conversation_urls) |
|
|
|
|
|
|
|
|
|
|
|
for convo in get_conversation_list(driver, offset=l): |
|
|
|
|
|
url = convo.get_attribute("data-href") |
|
|
|
|
|
conversation_urls.add(url) |
|
|
|
|
|
current_convo = convo |
|
|
|
|
|
|
|
|
|
|
|
if current_convo: |
|
|
|
|
|
scroll_to(driver, current_convo) |
|
|
|
|
|
|
|
|
|
|
|
print(l) |
|
|
|
|
|
print(len(conversation_urls)) |
|
|
|
|
|
if len(conversation_urls) == l: |
|
|
|
|
|
# no more conversations left |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
return list(conversation_urls) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_conversations(driver): |
|
|
def delete_conversations(driver): |
|
|
""" |
|
|
""" |
|
@ -30,5 +56,5 @@ def delete_conversations(driver): |
|
|
|
|
|
|
|
|
wait = WebDriverWait(driver, 20) |
|
|
wait = WebDriverWait(driver, 20) |
|
|
|
|
|
|
|
|
for convo_url in get_conversation_list(driver): |
|
|
for convo_url in get_all_conversations(driver): |
|
|
print(convo_url.get_property("data-href")) |
|
|
print(convo_url) |
|
|