Browse Source

Refactor types into separate module

pull/53/head
Wesley Kerfoot 5 years ago
parent
commit
91594a6cd4
  1. 7
      deletefb/tools/common.py
  2. 11
      deletefb/tools/likes.py
  3. 20
      deletefb/tools/wall.py
  4. 30
      deletefb/types.py

7
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

11
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

20
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"]

30
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)
Loading…
Cancel
Save