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"):
url = convo.get_attribute("href")
timestamp = None
date = None
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()
assert(conversation_name)
@ -50,7 +50,7 @@ def get_conversations(driver):
conversations.append(
Conversation(
url=url,
timestamp=timestamp,
date=date,
name=conversation_name
)
)
@ -88,7 +88,7 @@ def get_convo_messages(driver):
yield Message(
name=data_store.get("author"),
content=msg_text,
timestamp=data_store.get("timestamp")
date=data_store.get("timestamp")
)
def archive_conversation(driver, convo):
@ -134,11 +134,11 @@ def delete_conversations(driver, year=None):
convos = get_conversations(driver)
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
if year and convo.timestamp:
if convo.timestamp.year == int(year):
if year and convo.date:
if convo.date.year == int(year):
archive_conversation(driver, convo)
print(convo.messages)

10
deletefb/types.py

@ -2,9 +2,9 @@ import attr
import uuid
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
"""
try:
@ -35,7 +35,7 @@ class Comment:
class Conversation:
url = attr.ib()
name = attr.ib()
timestamp = attr.ib(converter=convert_timestamp)
date = attr.ib(converter=convert_date)
messages = attr.ib(default=[])
@attr.s
@ -43,8 +43,8 @@ class Message:
name = attr.ib()
content = attr.ib()
# Remove the last 3 digits from FB's timestamps. They are not standard.
timestamp = attr.ib(converter=lambda t: pendulum.from_timestamp(int(str(t)[0:-3])))
# Remove the last 3 digits from FB's dates. They are not standard.
date = attr.ib(converter=lambda t: pendulum.from_timestamp(int(str(t)[0:-3])))
@attr.s
class Page:

Loading…
Cancel
Save