|
@ -2,7 +2,8 @@ import time |
|
|
from selenium.webdriver.common.action_chains import ActionChains |
|
|
from selenium.webdriver.common.action_chains import ActionChains |
|
|
|
|
|
|
|
|
from .config import settings |
|
|
from .config import settings |
|
|
from .common import SELENIUM_EXCEPTIONS, archiver, click_button |
|
|
from .common import SELENIUM_EXCEPTIONS, click_button |
|
|
|
|
|
from .archive import archiver, Post |
|
|
|
|
|
|
|
|
# Used as a threshold to avoid running forever |
|
|
# Used as a threshold to avoid running forever |
|
|
MAX_POSTS = settings["MAX_POSTS"] |
|
|
MAX_POSTS = settings["MAX_POSTS"] |
|
@ -32,47 +33,52 @@ def delete_posts(driver, |
|
|
|
|
|
|
|
|
button_types = ["FeedDeleteOption", "HIDE_FROM_TIMELINE", "UNTAG"] |
|
|
button_types = ["FeedDeleteOption", "HIDE_FROM_TIMELINE", "UNTAG"] |
|
|
|
|
|
|
|
|
wall_log, archive_wall_post = archiver("wall") |
|
|
with archiver("wall") as archive_wall_post: |
|
|
|
|
|
while True: |
|
|
|
|
|
try: |
|
|
|
|
|
timeline_element = driver.find_element_by_class_name(post_button_sel) |
|
|
|
|
|
|
|
|
while True: |
|
|
post_content_element = driver.find_element_by_class_name(post_content_sel) |
|
|
try: |
|
|
post_content_ts = driver.find_element_by_class_name(post_timestamp_sel) |
|
|
timeline_element = driver.find_element_by_class_name(post_button_sel) |
|
|
|
|
|
|
|
|
|
|
|
post_content_element = driver.find_element_by_class_name(post_content_sel) |
|
|
|
|
|
post_content_ts = driver.find_element_by_class_name(post_timestamp_sel) |
|
|
|
|
|
|
|
|
|
|
|
archive_wall_post(post_content_element.text, timestamp=post_content_ts.text) |
|
|
# Archive the post |
|
|
|
|
|
archive_wall_post.archive( |
|
|
|
|
|
Post( |
|
|
|
|
|
content=post_content_element.text, |
|
|
|
|
|
date=post_content_ts.text |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
actions = ActionChains(driver) |
|
|
actions = ActionChains(driver) |
|
|
actions.move_to_element(timeline_element).click().perform() |
|
|
actions.move_to_element(timeline_element).click().perform() |
|
|
|
|
|
|
|
|
menu = driver.find_element_by_css_selector("#globalContainer > div.uiContextualLayerPositioner.uiLayer > div") |
|
|
menu = driver.find_element_by_css_selector("#globalContainer > div.uiContextualLayerPositioner.uiLayer > div") |
|
|
actions.move_to_element(menu).perform() |
|
|
actions.move_to_element(menu).perform() |
|
|
|
|
|
|
|
|
delete_button = None |
|
|
delete_button = None |
|
|
|
|
|
|
|
|
for button_type in button_types: |
|
|
for button_type in button_types: |
|
|
try: |
|
|
try: |
|
|
delete_button = menu.find_element_by_xpath("//a[@data-feed-option-name=\"{0}\"]".format(button_type)) |
|
|
delete_button = menu.find_element_by_xpath("//a[@data-feed-option-name=\"{0}\"]".format(button_type)) |
|
|
break |
|
|
break |
|
|
except SELENIUM_EXCEPTIONS: |
|
|
except SELENIUM_EXCEPTIONS: |
|
|
continue |
|
|
continue |
|
|
|
|
|
|
|
|
if not delete_button: |
|
|
if not delete_button: |
|
|
print("Could not find anything to delete") |
|
|
print("Could not find anything to delete") |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
actions.move_to_element(delete_button).click().perform() |
|
|
actions.move_to_element(delete_button).click().perform() |
|
|
confirmation_button = driver.find_element_by_class_name("layerConfirm") |
|
|
confirmation_button = driver.find_element_by_class_name("layerConfirm") |
|
|
|
|
|
|
|
|
click_button(driver, confirmation_button) |
|
|
click_button(driver, confirmation_button) |
|
|
|
|
|
|
|
|
except SELENIUM_EXCEPTIONS: |
|
|
except SELENIUM_EXCEPTIONS: |
|
|
continue |
|
|
continue |
|
|
else: |
|
|
else: |
|
|
break |
|
|
break |
|
|
wall_log.close() |
|
|
|
|
|
|
|
|
|
|
|
# Required to sleep the thread for a bit after using JS to click this button |
|
|
# Required to sleep the thread for a bit after using JS to click this button |
|
|
time.sleep(5) |
|
|
time.sleep(5) |
|
|
driver.refresh() |
|
|
driver.refresh() |
|
|