Browse Source

Merge 5ce35aa757 into 86403534b9

pull/143/merge
Wesley Kerfoot 3 years ago
committed by GitHub
parent
commit
25fd42be87
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      deletefb/deletefb.py
  2. 73
      deletefb/tools/activity.py
  3. 6
      deletefb/tools/wall.py
  4. 2
      run.sh

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)

73
deletefb/tools/activity.py

@ -0,0 +1,73 @@
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
from calendar import month_name
months = [m for m in month_name if m]
import time
# Used as a threshold to avoid running forever
MAX_POSTS = settings["MAX_POSTS"]
def get_load_more(driver):
"""
Click the "Load more from X" button repeatedly
"""
button_expr = f"//div[contains(text(), 'Load more from')]"
print("Trying to load more")
while True:
try:
wait_xpath(driver, button_expr)
driver.find_element_by_xpath(button_expr).click()
except SELENIUM_EXCEPTIONS:
break
def get_timeslices(driver):
"""
Get a list of the time slices Facebook is going to let us click.
"""
slice_expr = "//header"
wait_xpath(driver, slice_expr)
for ts in driver.find_elements_by_xpath(slice_expr):
if any(w in months for w in ts.text.strip().split()):
yield ts
try:
int(ts.text.strip())
if len(ts.text.strip()) == 4: # it's a year
yield ts
except ValueError:
continue
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")
#print(get_load_more(driver))
actions = ActionChains(driver)
for ts in get_timeslices(driver):
# Need to figure out how to ignore the ones with nothing in them
print(ts.text)
actions.move_to_element(ts)
get_load_more(driver)
time.sleep(1000)
#with archiver("activity") as archive_wall_post:

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}/timeline?year={1}".format(user_profile_url, year)
user_profile_url = force_mobile(user_profile_url)
driver.get(user_profile_url)

2
run.sh

@ -1,2 +1,2 @@
#!/bin/bash
/usr/bin/python3 -m deletefb.deletefb -E $EMAIL -P $PASS -U $URL
python3 -m deletefb.deletefb -E $EMAIL -P $PASS -U $URL

Loading…
Cancel
Save