From 723d90981d55b99cc01ee1252d65f7a19908ad81 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Tue, 16 Jul 2019 23:24:05 -0400 Subject: [PATCH] Try parsing conversation timestamps, if they exist --- deletefb/tools/common.py | 5 +++++ deletefb/tools/conversations.py | 15 ++++++++++----- deletefb/types.py | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index 5c14118..301d5f0 100644 --- a/deletefb/tools/common.py +++ b/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: diff --git a/deletefb/tools/conversations.py b/deletefb/tools/conversations.py index e51790e..7ea3ee5 100644 --- a/deletefb/tools/conversations.py +++ b/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: diff --git a/deletefb/types.py b/deletefb/types.py index 44672bb..429f3ba 100644 --- a/deletefb/types.py +++ b/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)