From 91594a6cd47c36e6128302eb0abe1daf7262ee98 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 9 Jun 2019 18:57:41 -0400 Subject: [PATCH] Refactor types into separate module --- deletefb/tools/common.py | 7 ------- deletefb/tools/likes.py | 11 ++--------- deletefb/tools/wall.py | 20 ++------------------ deletefb/types.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 deletefb/types.py diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index fb08daf..b508afc 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -6,7 +6,6 @@ from selenium.common.exceptions import ( TimeoutException ) -import datetime import json import logging import logging.config @@ -19,12 +18,6 @@ SELENIUM_EXCEPTIONS = ( TimeoutException ) -def timestamp_now(): - """ - Returns: a timestamp for this instant, in ISO 8601 format - """ - return datetime.datetime.isoformat(datetime.datetime.now()) - def click_button(driver, el): """ Click a button using Javascript diff --git a/deletefb/tools/likes.py b/deletefb/tools/likes.py index 0ebce33..63ade1e 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -1,20 +1,13 @@ from .archive import archiver -from .common import SELENIUM_EXCEPTIONS, logger, click_button, timestamp_now +from ..types import Page +from .common import SELENIUM_EXCEPTIONS, logger, click_button from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait -import attr - LOG = logger(__name__) -# Data type definitions of posts and comments -@attr.s -class Page: - name = attr.ib() - date = attr.ib(factory=timestamp_now) - def load_likes(driver, profile_url): """ Loads the page that lists all pages you like diff --git a/deletefb/tools/wall.py b/deletefb/tools/wall.py index 2b01816..890bae0 100644 --- a/deletefb/tools/wall.py +++ b/deletefb/tools/wall.py @@ -1,26 +1,10 @@ +from ..types import Post from .archive import archiver -from .common import SELENIUM_EXCEPTIONS, click_button, timestamp_now +from .common import SELENIUM_EXCEPTIONS, click_button from .config import settings from selenium.webdriver.common.action_chains import ActionChains -import attr import time -import uuid - -# Data type definitions of posts and comments -@attr.s -class Post: - content = attr.ib() - comments = attr.ib(default=[]) - date = attr.ib(factory=timestamp_now) - name = attr.ib(factory=lambda: uuid.uuid4().hex) - -@attr.s -class Comment: - commenter = attr.ib() - content = attr.ib() - date = attr.ib(factory=timestamp_now) - name = attr.ib(factory=lambda: uuid.uuid4().hex) # Used as a threshold to avoid running forever MAX_POSTS = settings["MAX_POSTS"] diff --git a/deletefb/types.py b/deletefb/types.py new file mode 100644 index 0000000..f171a9c --- /dev/null +++ b/deletefb/types.py @@ -0,0 +1,30 @@ +import attr +import time +import uuid +import datetime + +def timestamp_now(): + """ + Returns: a timestamp for this instant, in ISO 8601 format + """ + return datetime.datetime.isoformat(datetime.datetime.now()) + +# Data type definitions of posts and comments +@attr.s +class Post: + content = attr.ib() + comments = attr.ib(default=[]) + date = attr.ib(factory=timestamp_now) + name = attr.ib(factory=lambda: uuid.uuid4().hex) + +@attr.s +class Comment: + commenter = attr.ib() + content = attr.ib() + date = attr.ib(factory=timestamp_now) + name = attr.ib(factory=lambda: uuid.uuid4().hex) + +@attr.s +class Page: + name = attr.ib() + date = attr.ib(factory=timestamp_now)