|
@@ -1,38 +1,46 @@
|
1
|
1
|
from datetime import datetime
|
2
|
2
|
from typing import Any, List
|
3
|
3
|
from uuid import uuid4
|
4
|
|
-from pydantic import BaseModel, PrivateAttr, computed_field
|
|
4
|
+from pydantic import BaseModel, Field, PrivateAttr, computed_field, validator
|
|
5
|
+
|
5
|
6
|
|
6
|
7
|
class Reaction(BaseModel):
|
7
|
8
|
reaction: str
|
8
|
9
|
actor: str
|
9
|
10
|
|
|
11
|
+
|
10
|
12
|
class AudioFile(BaseModel):
|
11
|
13
|
uri: str
|
12
|
14
|
creation_timestamp: int
|
13
|
15
|
|
|
16
|
+
|
14
|
17
|
class Video(BaseModel):
|
15
|
18
|
uri: str
|
16
|
19
|
creation_timestamp: int
|
17
|
20
|
|
|
21
|
+
|
18
|
22
|
class Photo(BaseModel):
|
19
|
23
|
uri: str
|
20
|
24
|
creation_timestamp: int
|
21
|
25
|
|
|
26
|
+
|
22
|
27
|
class Gif(BaseModel):
|
23
|
28
|
uri: str
|
24
|
29
|
|
|
30
|
+
|
25
|
31
|
class Share(BaseModel):
|
26
|
32
|
link: str
|
27
|
33
|
share_text: str
|
28
|
34
|
|
|
35
|
+
|
29
|
36
|
class Sticker(BaseModel):
|
30
|
37
|
uri: str
|
31
|
38
|
ai_stickers: List[Any]
|
32
|
39
|
|
|
40
|
+
|
33
|
41
|
class Message(BaseModel):
|
34
|
42
|
sender_name: str
|
35
|
|
- timestamp_ms: int
|
|
43
|
+ date_time: datetime = Field(alias="timestamp_ms")
|
36
|
44
|
content: str | None = None
|
37
|
45
|
sticker: Sticker | None = None
|
38
|
46
|
share: Share | None = None
|
|
@@ -47,16 +55,20 @@ class Message(BaseModel):
|
47
|
55
|
|
48
|
56
|
_id: str = PrivateAttr(default_factory=lambda: str(uuid4()))
|
49
|
57
|
|
50
|
|
-
|
51
|
58
|
def __str__(self) -> str:
|
52
|
|
- dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
|
53
|
|
- dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
|
|
59
|
+ dt_str = self.date_time.strftime("%d/%m/%Y, %H:%M:%S")
|
54
|
60
|
return f"{self.sender_name}({dt_str}) : {self.content}"
|
55
|
61
|
|
56
|
62
|
def __hash__(self) -> int:
|
57
|
63
|
return hash(self.item_id)
|
58
|
|
-
|
|
64
|
+
|
59
|
65
|
@computed_field
|
60
|
66
|
@property
|
61
|
67
|
def item_id(self) -> str:
|
62
|
|
- return self._id
|
|
68
|
+ return self._id
|
|
69
|
+
|
|
70
|
+ @validator("date_time", pre=True, always=True)
|
|
71
|
+ def parse_timestamp(cls, v):
|
|
72
|
+ if isinstance(v, int):
|
|
73
|
+ return datetime.fromtimestamp(v / 1000)
|
|
74
|
+ return v
|