1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- from datetime import datetime
- from typing import Any, List
- from uuid import uuid4
- from pydantic import BaseModel, PrivateAttr, computed_field
-
- class Reaction(BaseModel):
- reaction: str
- actor: str
-
- class AudioFile(BaseModel):
- uri: str
- creation_timestamp: int
-
- class Video(BaseModel):
- uri: str
- creation_timestamp: int
-
- class Photo(BaseModel):
- uri: str
- creation_timestamp: int
-
- class Gif(BaseModel):
- uri: str
-
- class Share(BaseModel):
- link: str
- share_text: str
-
- class Sticker(BaseModel):
- uri: str
- ai_stickers: List[Any]
-
- class Message(BaseModel):
- sender_name: str
- timestamp_ms: int
- content: str | None = None
- sticker: Sticker | None = None
- share: Share | None = None
- photos: List[Photo] | None = None
- videos: List[Video] | None = None
- gifs: List[Gif] | None = None
- audio_files: List[AudioFile] | None = None
- call_duration: int | None = None
- reactions: List[Reaction] | None = None
- is_unsent: bool | None = None
- is_geoblocked_for_viewer: bool
-
- _id: str = PrivateAttr(default_factory=lambda: str(uuid4()))
-
-
- def __str__(self) -> str:
- dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
- dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
- return f"{self.sender_name}({dt_str}) : {self.content}"
-
- def __hash__(self) -> int:
- return hash(self.item_id)
-
- @computed_field
- @property
- def item_id(self) -> str:
- return self._id
|