Browse Source

Try parsing conversation timestamps, if they exist

pull/72/head
Wesley Kerfoot 5 years ago
parent
commit
723d90981d
  1. 5
      deletefb/tools/common.py
  2. 15
      deletefb/tools/conversations.py
  3. 1
      deletefb/types.py

5
deletefb/tools/common.py

@ -5,11 +5,13 @@ from selenium.common.exceptions import (
TimeoutException,
JavascriptException
)
from arrow.parser import ParserError
import json
import logging
import logging.config
import os
import arrow
SELENIUM_EXCEPTIONS = (
NoSuchElementException,
@ -32,6 +34,9 @@ def scroll_to(driver, el):
except SELENIUM_EXCEPTIONS:
return
def parse_ts(text):
return arrow.get(text, "DD/M/YYYY")
def logger(name):
"""
Args:

15
deletefb/tools/conversations.py

@ -1,11 +1,10 @@
from .archive import archiver
from ..types import Conversation
from .common import SELENIUM_EXCEPTIONS, logger, scroll_to, click_button
from .common import SELENIUM_EXCEPTIONS, logger, parse_ts, ParserError
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 time import sleep
LOG = logger(__name__)
@ -30,10 +29,16 @@ def get_conversations(driver):
for convo in driver.find_elements_by_xpath("//a"):
url = convo.get_attribute("href")
if url and "messages/read" in url:
yield url
try:
print(parse_ts(convo.find_element_by_xpath("../../..//abbr").text))
except ParserError:
print("Failed to parse timestamp")
continue
try:
next_url = driver.find_element_by_id("see_older_threads").find_element_by_xpath("a").get_attribute("href")
next_url = (driver.find_element_by_id("see_older_threads").
find_element_by_xpath("a").
get_attribute("href"))
except SELENIUM_EXCEPTIONS:
break
if not next_url:

1
deletefb/types.py

@ -25,6 +25,7 @@ class Comment:
@attr.s
class Conversation:
url = attr.ib()
recipient = attr.ib()
name = attr.ib()
last_message_time = attr.ib(factory=timestamp_now)

Loading…
Cancel
Save