Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

message.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from datetime import datetime
  2. from typing import Any, List
  3. from pydantic import BaseModel
  4. import pytz
  5. utc=pytz.UTC
  6. class Reaction(BaseModel):
  7. reaction: str
  8. actor: str
  9. class AudioFile(BaseModel):
  10. uri: str
  11. creation_timestamp: int
  12. class Video(BaseModel):
  13. uri: str
  14. creation_timestamp: int
  15. class Photo(BaseModel):
  16. uri: str
  17. creation_timestamp: int
  18. class Gif(BaseModel):
  19. uri: str
  20. class Share(BaseModel):
  21. link: str
  22. share_text: str
  23. class Sticker(BaseModel):
  24. uri: str
  25. ai_stickers: List[Any]
  26. class Message(BaseModel):
  27. sender_name: str
  28. timestamp_ms: int
  29. content: str | None = None
  30. sticker: Sticker | None = None
  31. share: Share | None = None
  32. photos: List[Photo] | None = None
  33. videos: List[Video] | None = None
  34. gifs: List[Gif] | None = None
  35. audio_files: List[AudioFile] | None = None
  36. call_duration: int | None = None
  37. reactions: List[Reaction] | None = None
  38. is_unsent: bool | None = None
  39. is_geoblocked_for_viewer: bool
  40. @property
  41. def date(self) -> datetime:
  42. return utc.localize(datetime.fromtimestamp(self.timestamp_ms / 1000))
  43. def __str__(self) -> str:
  44. dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
  45. dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
  46. return f"{self.sender_name}({dt_str}) : {self.content}"
  47. def __hash__(self) -> int:
  48. return hash(self.sender_name + str(self.timestamp_ms))