Browse Source

Try parsing conversation timestamps, if they exist

pull/72/head
Wesley Kerfoot 6 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, TimeoutException,
JavascriptException JavascriptException
) )
from arrow.parser import ParserError
import json import json
import logging import logging
import logging.config import logging.config
import os import os
import arrow
SELENIUM_EXCEPTIONS = ( SELENIUM_EXCEPTIONS = (
NoSuchElementException, NoSuchElementException,
@ -32,6 +34,9 @@ def scroll_to(driver, el):
except SELENIUM_EXCEPTIONS: except SELENIUM_EXCEPTIONS:
return return
def parse_ts(text):
return arrow.get(text, "DD/M/YYYY")
def logger(name): def logger(name):
""" """
Args: Args:

15
deletefb/tools/conversations.py

@ -1,11 +1,10 @@
from .archive import archiver from .archive import archiver
from ..types import Conversation 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.common.by import By
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
LOG = logger(__name__) LOG = logger(__name__)
@ -30,10 +29,16 @@ 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")
if url and "messages/read" in url: if url and "messages/read" in url:
yield url
try: try:
next_url = driver.find_element_by_id("see_older_threads").find_element_by_xpath("a").get_attribute("href") 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"))
except SELENIUM_EXCEPTIONS: except SELENIUM_EXCEPTIONS:
break break
if not next_url: if not next_url:

1
deletefb/types.py

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

Loading…
Cancel
Save