5 changed files with 49 additions and 30 deletions
@ -1,35 +1,39 @@ |
|||
import attr |
|||
import uuid |
|||
import datetime |
|||
import pendulum |
|||
|
|||
def timestamp_now(): |
|||
""" |
|||
Returns: a timestamp for this instant, in ISO 8601 format |
|||
""" |
|||
return datetime.datetime.isoformat(datetime.datetime.now()) |
|||
def convert_timestamp(text): |
|||
try: |
|||
return pendulum.from_format(text, "DD/M/YYYY") |
|||
except ValueError: |
|||
try: |
|||
return (pendulum.from_format(text, "DD MMM") |
|||
.set(year=pendulum.now().year)) |
|||
except ValueError: |
|||
return None |
|||
|
|||
# Data type definitions of posts and comments |
|||
@attr.s |
|||
class Post: |
|||
content = attr.ib() |
|||
comments = attr.ib(default=[]) |
|||
date = attr.ib(factory=timestamp_now) |
|||
date = attr.ib(factory=pendulum.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) |
|||
date = attr.ib(factory=pendulum.now) |
|||
name = attr.ib(factory=lambda: uuid.uuid4().hex) |
|||
|
|||
@attr.s |
|||
class Conversation: |
|||
url = attr.ib() |
|||
name = attr.ib() |
|||
timestamp = attr.ib(default=None) |
|||
timestamp = attr.ib(converter=convert_timestamp) |
|||
|
|||
@attr.s |
|||
class Page: |
|||
name = attr.ib() |
|||
date = attr.ib(factory=timestamp_now) |
|||
date = attr.ib(factory=pendulum.now) |
|||
|
@ -1,13 +1,25 @@ |
|||
attrs==19.1.0 |
|||
bitarray==0.9.3 |
|||
bleach==3.1.0 |
|||
certifi==2018.11.29 |
|||
chardet==3.0.4 |
|||
docutils==0.14 |
|||
idna==2.8 |
|||
pendulum==2.0.5 |
|||
pkginfo==1.5.0.1 |
|||
pybloom-live==3.0.0 |
|||
Pygments==2.4.2 |
|||
python-dateutil==2.8.0 |
|||
pytzdata==2019.2 |
|||
readme-renderer==24.0 |
|||
requests==2.22.0 |
|||
requests-file==1.4.3 |
|||
requests-toolbelt==0.9.1 |
|||
selenium==3.141.0 |
|||
selenium-requests==1.3 |
|||
six==1.12.0 |
|||
tldextract==2.2.0 |
|||
tqdm==4.32.2 |
|||
twine==1.13.0 |
|||
urllib3==1.25.2 |
|||
webencodings==0.5.1 |
|||
|
Loading…
Reference in new issue