|
@ -1,7 +1,9 @@ |
|
|
from .archive import archiver |
|
|
from .archive import archiver |
|
|
from ..types import Conversation, Message |
|
|
from ..types import Conversation, Message |
|
|
from .common import SELENIUM_EXCEPTIONS, logger, click_button, wait_xpath |
|
|
from .common import SELENIUM_EXCEPTIONS, logger, click_button, wait_xpath |
|
|
|
|
|
from .config import settings |
|
|
from selenium.webdriver.common.action_chains import ActionChains |
|
|
from selenium.webdriver.common.action_chains import ActionChains |
|
|
|
|
|
from selenium.webdriver.support.ui import Select |
|
|
from pendulum import now |
|
|
from pendulum import now |
|
|
from json import loads |
|
|
from json import loads |
|
|
from time import sleep |
|
|
from time import sleep |
|
@ -114,10 +116,22 @@ def delete_conversation(driver, convo): |
|
|
|
|
|
|
|
|
actions = ActionChains(driver) |
|
|
actions = ActionChains(driver) |
|
|
|
|
|
|
|
|
delete_button = driver.find_element_by_xpath("//select/option[contains(text(), 'Delete')]") |
|
|
menu_select = Select(driver.find_element_by_xpath("//select/option[contains(text(), 'Delete')]/..")) |
|
|
|
|
|
|
|
|
|
|
|
for i, option in enumerate(menu_select.options): |
|
|
|
|
|
print(option.text) |
|
|
|
|
|
if option.text.strip() == "Delete": |
|
|
|
|
|
menu_select.select_by_index(i) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wait_xpath(driver, "//h2[contains(text(), 'Delete conversation')]") |
|
|
|
|
|
|
|
|
|
|
|
delete_button = driver.find_element_by_xpath("//a[contains(text(), 'Delete')][@role='button']") |
|
|
|
|
|
|
|
|
actions.move_to_element(delete_button).click().perform() |
|
|
actions.move_to_element(delete_button).click().perform() |
|
|
|
|
|
|
|
|
|
|
|
sleep(10000) |
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
def extract_convo(driver, convo): |
|
|
def extract_convo(driver, convo): |
|
@ -137,7 +151,7 @@ def extract_convo(driver, convo): |
|
|
|
|
|
|
|
|
return convo |
|
|
return convo |
|
|
|
|
|
|
|
|
def traverse_conversations(driver, year=None, delete=False): |
|
|
def traverse_conversations(driver, year=None): |
|
|
""" |
|
|
""" |
|
|
Remove all conversations within a specified range |
|
|
Remove all conversations within a specified range |
|
|
""" |
|
|
""" |
|
@ -154,14 +168,18 @@ def traverse_conversations(driver, year=None, delete=False): |
|
|
if year and convo.date: |
|
|
if year and convo.date: |
|
|
if convo.date.year == int(year): |
|
|
if convo.date.year == int(year): |
|
|
extract_convo(driver, convo) |
|
|
extract_convo(driver, convo) |
|
|
archive_convo.archive(convo) |
|
|
|
|
|
if delete: |
|
|
if settings["ARCHIVE"]: |
|
|
delete_conversation(driver, convo) |
|
|
archive_convo.archive(convo) |
|
|
|
|
|
|
|
|
|
|
|
delete_conversation(driver, convo) |
|
|
|
|
|
|
|
|
# Otherwise we're looking at all convos |
|
|
# Otherwise we're looking at all convos |
|
|
elif not year: |
|
|
elif not year: |
|
|
extract_convo(driver, convo) |
|
|
extract_convo(driver, convo) |
|
|
archive_convo.archive(convo) |
|
|
|
|
|
if delete: |
|
|
if settings["ARCHIVE"]: |
|
|
delete_conversation(driver, convo) |
|
|
archive_convo.archive(convo) |
|
|
|
|
|
|
|
|
|
|
|
delete_conversation(driver, convo) |
|
|
|
|
|
|
|
|