From f159937e1deeaee8614ebf32395687f64528b6eb Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 9 Jun 2019 17:16:34 -0400 Subject: [PATCH] Fix bugs with archiver --- deletefb/tools/archive.py | 2 +- deletefb/tools/common.py | 7 +++++++ deletefb/tools/likes.py | 5 ++--- deletefb/tools/wall.py | 7 +++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/deletefb/tools/archive.py b/deletefb/tools/archive.py index 43a8f2b..831bf6e 100644 --- a/deletefb/tools/archive.py +++ b/deletefb/tools/archive.py @@ -32,7 +32,7 @@ class Archive: print("Archiving {0}".format(content)) if content.name not in self._bloom_filter: - self.archive_file.write(json.dumps(attr.asdict(content))) + self.archive_file.write(json.dumps(attr.asdict(content)) + "\n") self._bloom_filter.add(content.name) return diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index b508afc..fb08daf 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -6,6 +6,7 @@ from selenium.common.exceptions import ( TimeoutException ) +import datetime import json import logging import logging.config @@ -18,6 +19,12 @@ 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 afeed8e..0ebce33 100644 --- a/deletefb/tools/likes.py +++ b/deletefb/tools/likes.py @@ -1,12 +1,11 @@ from .archive import archiver -from .common import SELENIUM_EXCEPTIONS, logger, click_button +from .common import SELENIUM_EXCEPTIONS, logger, click_button, timestamp_now 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 -import datetime LOG = logger(__name__) @@ -14,7 +13,7 @@ LOG = logger(__name__) @attr.s class Page: name = attr.ib() - date = attr.ib(factory=datetime.datetime.now) + date = attr.ib(factory=timestamp_now) def load_likes(driver, profile_url): """ diff --git a/deletefb/tools/wall.py b/deletefb/tools/wall.py index 46a92c8..2b01816 100644 --- a/deletefb/tools/wall.py +++ b/deletefb/tools/wall.py @@ -1,10 +1,9 @@ from .archive import archiver -from .common import SELENIUM_EXCEPTIONS, click_button +from .common import SELENIUM_EXCEPTIONS, click_button, timestamp_now from .config import settings from selenium.webdriver.common.action_chains import ActionChains import attr -import datetime import time import uuid @@ -13,14 +12,14 @@ import uuid class Post: content = attr.ib() comments = attr.ib(default=[]) - date = attr.ib(factory=datetime.datetime.now) + 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=datetime.datetime.now) + date = attr.ib(factory=timestamp_now) name = attr.ib(factory=lambda: uuid.uuid4().hex) # Used as a threshold to avoid running forever