Browse Source

Rename `timestamp` to `date` to be consistent

pull/72/head
Wesley Kerfoot 5 years ago
parent
commit
b2e4a92e82
  1. 14
      deletefb/tools/conversations.py
  2. 10
      deletefb/types.py

14
deletefb/tools/conversations.py

@ -37,11 +37,11 @@ def get_conversations(driver):
for convo in driver.find_elements_by_xpath("//a"): for convo in driver.find_elements_by_xpath("//a"):
url = convo.get_attribute("href") url = convo.get_attribute("href")
timestamp = None date = None
if url and "messages/read" in url: if url and "messages/read" in url:
timestamp = convo.find_element_by_xpath("../../..//abbr").text date = convo.find_element_by_xpath("../../..//abbr").text
conversation_name = convo.find_element_by_xpath("../../../div/div/header/h3").text.strip() conversation_name = convo.find_element_by_xpath("../../../div/div/header/h3").text.strip()
assert(conversation_name) assert(conversation_name)
@ -50,7 +50,7 @@ def get_conversations(driver):
conversations.append( conversations.append(
Conversation( Conversation(
url=url, url=url,
timestamp=timestamp, date=date,
name=conversation_name name=conversation_name
) )
) )
@ -88,7 +88,7 @@ def get_convo_messages(driver):
yield Message( yield Message(
name=data_store.get("author"), name=data_store.get("author"),
content=msg_text, content=msg_text,
timestamp=data_store.get("timestamp") date=data_store.get("timestamp")
) )
def archive_conversation(driver, convo): def archive_conversation(driver, convo):
@ -134,11 +134,11 @@ def delete_conversations(driver, year=None):
convos = get_conversations(driver) convos = get_conversations(driver)
for convo in convos: for convo in convos:
# If the year is set and there is a timestamp # If the year is set and there is a date
# Then we want to only look at convos from this year # Then we want to only look at convos from this year
if year and convo.timestamp: if year and convo.date:
if convo.timestamp.year == int(year): if convo.date.year == int(year):
archive_conversation(driver, convo) archive_conversation(driver, convo)
print(convo.messages) print(convo.messages)

10
deletefb/types.py

@ -2,9 +2,9 @@ import attr
import uuid import uuid
import pendulum import pendulum
def convert_timestamp(text): def convert_date(text):
""" """
Tries to parse a timestamp into a DateTime instance Tries to parse a date into a DateTime instance
Returns `None` if it cannot be parsed Returns `None` if it cannot be parsed
""" """
try: try:
@ -35,7 +35,7 @@ class Comment:
class Conversation: class Conversation:
url = attr.ib() url = attr.ib()
name = attr.ib() name = attr.ib()
timestamp = attr.ib(converter=convert_timestamp) date = attr.ib(converter=convert_date)
messages = attr.ib(default=[]) messages = attr.ib(default=[])
@attr.s @attr.s
@ -43,8 +43,8 @@ class Message:
name = attr.ib() name = attr.ib()
content = attr.ib() content = attr.ib()
# Remove the last 3 digits from FB's timestamps. They are not standard. # Remove the last 3 digits from FB's dates. They are not standard.
timestamp = attr.ib(converter=lambda t: pendulum.from_timestamp(int(str(t)[0:-3]))) date = attr.ib(converter=lambda t: pendulum.from_timestamp(int(str(t)[0:-3])))
@attr.s @attr.s
class Page: class Page:

Loading…
Cancel
Save