This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
types.py
55 lines (47 loc) · 1.34 KB
/
types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import attr
import uuid
import pendulum
from datetime import datetime
def convert_date(text):
"""
Tries to parse a date into a DateTime instance
Returns `None` if it cannot be parsed
"""
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=pendulum.now)
name = attr.ib(factory=lambda: uuid.uuid4().hex)
@attr.s
class Comment:
commenter = attr.ib()
content = attr.ib()
date = attr.ib(factory=pendulum.now)
name = attr.ib(factory=lambda: uuid.uuid4().hex)
@attr.s
class Conversation:
url = attr.ib()
name = attr.ib()
date : datetime = attr.ib(converter=convert_date)
messages = attr.ib(default=[])
image_links = attr.ib(default=[])
@attr.s
class Message:
name = attr.ib()
content = attr.ib()
# Remove the last 3 digits from FB's dates. They are not standard.
date : datetime = attr.ib(converter=lambda t: pendulum.from_timestamp(int(str(t)[0:-3])))
@attr.s
class Page:
name = attr.ib()
date = attr.ib(factory=pendulum.now)