Browse Source

activity log (not working yet)

pull/143/head
Wesley Kerfoot 4 years ago
parent
commit
d6b3b240f4
  1. 11
      deletefb/deletefb.py
  2. 107
      deletefb/tools/activity.py
  3. 6
      deletefb/tools/wall.py

11
deletefb/deletefb.py

@ -6,6 +6,7 @@ from .tools.login import login
from .tools.wall import delete_posts
from .tools.conversations import traverse_conversations
from .tools.comments import delete_comments
from .tools.activity import delete_activity
from .quit_driver import quit_driver_and_reap_children
import argparse
@ -24,8 +25,8 @@ def run_delete():
default="wall",
dest="mode",
type=str,
choices=["wall", "unlike_pages", "conversations"],
help="The mode you want to run in. Default is `wall' which deletes wall posts"
choices=["wall", "unlike_pages", "conversations", "activity"],
help="The mode you want to run in. Default is `wall' which deletes all wall posts"
)
parser.add_argument(
@ -104,7 +105,7 @@ def run_delete():
settings["ARCHIVE"] = not args.archive_off
if args.year and args.mode not in ("wall", "conversations"):
if args.year and args.mode not in ("activity", "conversations"):
parser.error("The --year option is not supported in this mode")
args_user_password = args.password or getpass.getpass('Enter your password: ')
@ -122,9 +123,11 @@ def run_delete():
delete_posts(
driver,
args.profile_url,
year=args.year
)
elif args.mode == "activity":
delete_activity(driver, year=args.year)
elif args.mode == "unlike_pages":
unlike_pages(driver, args.profile_url)

107
deletefb/tools/activity.py

@ -0,0 +1,107 @@
from ..types import Post
from .archive import archiver
from .common import SELENIUM_EXCEPTIONS, click_button, wait_xpath, force_mobile
from .config import settings
from selenium.webdriver.common.action_chains import ActionChains
import time
# Used as a threshold to avoid running forever
MAX_POSTS = settings["MAX_POSTS"]
def delete_activity(driver,
year=None):
"""
Deletes or hides all activity related to posts.
Args:
driver: seleniumrequests.Chrome Driver instance
year: optional int YYYY year
"""
driver.get("https://m.facebook.com/allactivity/?category_key=statuscluster")
time.sleep(1000)
finished = False
with archiver("wall") as archive_wall_post:
for _ in range(MAX_POSTS):
if finished:
break
post_button_sel = "_4s19"
post_content_sel = "userContent"
post_timestamp_sel = "timestampContent"
confirmation_button_exp = "//div[contains(@data-sigil, 'undo-content')]//*/a[contains(@href, 'direct_action_execute')]"
# Cannot return a text node, so it returns the parent.
# Tries to be pretty resilient against DOM re-organizations
timestamp_exp = "//article//*/header//*/div/a[contains(@href, 'story_fbid')]//text()/.."
button_types = ["Delete post", "Remove tag", "Hide from timeline"]
while True:
try:
try:
timeline_element = driver.find_element_by_xpath("//div[@data-sigil='story-popup-causal-init']/a")
except SELENIUM_EXCEPTIONS:
print("Could not find any posts")
finished = True
break
post_content_element = driver.find_element_by_xpath("//article/div[@class='story_body_container']/div")
post_content_ts = driver.find_element_by_xpath(timestamp_exp)
if not (post_content_element or post_content_ts):
break
# Archive the post
archive_wall_post.archive(
Post(
content=post_content_element.text,
date=post_content_ts.text
)
)
actions = ActionChains(driver)
actions.move_to_element(timeline_element).click().perform()
# Wait until the buttons show up
wait_xpath(driver, "//*[contains(@data-sigil, 'removeStoryButton')]")
delete_button = None
# Search for visible buttons in priority order
# Delete -> Untag -> Hide
for button_type in button_types:
try:
delete_button = driver.find_element_by_xpath("//*[text()='{0}']".format(button_type))
if not delete_button.is_displayed():
continue
break
except SELENIUM_EXCEPTIONS as e:
print(e)
continue
if not delete_button:
print("Could not find anything to delete")
break
click_button(driver, delete_button)
wait_xpath(driver, confirmation_button_exp)
confirmation_button = driver.find_element_by_xpath(confirmation_button_exp)
print(confirmation_button)
click_button(driver, confirmation_button)
except SELENIUM_EXCEPTIONS as e:
print(e)
continue
else:
break
# Required to sleep the thread for a bit after using JS to click this button
time.sleep(5)
driver.refresh()

6
deletefb/tools/wall.py

@ -10,8 +10,7 @@ import time
MAX_POSTS = settings["MAX_POSTS"]
def delete_posts(driver,
user_profile_url,
year=None):
user_profile_url):
"""
Deletes or hides all posts from the wall
@ -21,9 +20,6 @@ def delete_posts(driver,
year: optional int YYYY year
"""
if year is not None:
user_profile_url = "{0}/?year={1}".format(force_mobile(user_profile_url), year)
user_profile_url = force_mobile(user_profile_url)
driver.get(user_profile_url)

Loading…
Cancel
Save