From b4ea9729e023a7a487781ed525bd7a58040579f6 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 24 Jan 2021 19:38:00 -0500 Subject: [PATCH] refactoring activity --- deletefb/tools/activity.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/deletefb/tools/activity.py b/deletefb/tools/activity.py index 37cbaaa..1c5a5c0 100644 --- a/deletefb/tools/activity.py +++ b/deletefb/tools/activity.py @@ -36,6 +36,9 @@ def get_timeslices(driver): slice_expr = "//header" wait_xpath(driver, slice_expr) + + print("Loaded") + for ts in driver.find_elements_by_xpath(slice_expr): if any(w in months for w in ts.text.strip().split()): yield ts @@ -58,16 +61,35 @@ def delete_activity(driver, driver.get("https://m.facebook.com/allactivity/?category_key=statuscluster") - #print(get_load_more(driver)) + if year is None: + print("Deleting all years") + years = [elem.text.strip() for elem in get_timeslices(driver)] + else: + years = [elem.text.strip() for elem in get_timeslices(driver) if year in elem.text.strip()] actions = ActionChains(driver) - for ts in get_timeslices(driver): + print(years) + + for year in years: + year_elems = [y for y in get_timeslices(driver) if y.text.strip() == year] + + if not year_elems: + raise ValueError("Non-existent year") # FIXME use a better exception + + year_elem = year_elems[0] + # Need to figure out how to ignore the ones with nothing in them - print(ts.text) - actions.move_to_element(ts) + print(f"Deleting activity from {year_elem.text}") + + actions.move_to_element(year_elem) + year_elem.click() + get_load_more(driver) - time.sleep(1000) + time.sleep(10) + + driver.refresh() + #with archiver("activity") as archive_wall_post: