Browse Source

Support for filtering conversations by year

pull/72/head
Wesley Kerfoot 5 years ago
parent
commit
b74dd81e0d
  1. 6
      deletefb/deletefb.py
  2. 15
      deletefb/tools/conversations.py
  3. 4
      deletefb/types.py

6
deletefb/deletefb.py

@ -93,8 +93,8 @@ def run_delete():
settings["ARCHIVE"] = not args.archive_off
if args.year and args.mode != "wall":
parser.error("The --year option is only supported in wall mode")
if args.year and args.mode not in ("wall", "conversations"):
parser.error("The --year option is not supported in this mode")
args_user_password = args.password or getpass.getpass('Enter your password: ')
@ -119,7 +119,7 @@ def run_delete():
delete_comments(driver, args.profile_url)
elif args.mode == "conversations":
delete_conversations(driver)
delete_conversations(driver, year=args.year)
else:
print("Please enter a valid mode")

15
deletefb/tools/conversations.py

@ -5,6 +5,7 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from pendulum import now
LOG = logger(__name__)
@ -64,7 +65,7 @@ def get_conversations(driver):
return conversations
def delete_conversations(driver, older_than=None):
def delete_conversations(driver, year=None):
"""
Remove all conversations within a specified range
"""
@ -74,4 +75,14 @@ def delete_conversations(driver, older_than=None):
convos = get_conversations(driver)
for convo in convos:
print(convo)
# If the year is set and there is a timestamp
# Then we want to only look at convos from this year
if year and convo.timestamp:
if convo.timestamp.year == int(year):
print(convo)
# Otherwise we're looking at all convos
elif not year:
print(convo)

4
deletefb/types.py

@ -3,6 +3,10 @@ import uuid
import pendulum
def convert_timestamp(text):
"""
Tries to parse a timestamp into a DateTime instance
Returns `None` if it cannot be parsed
"""
try:
return pendulum.from_format(text, "DD/M/YYYY")
except ValueError:

Loading…
Cancel
Save