twitter_v2_types.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. from typing import List, Dict, Union, Optional
  2. from dataclasses import dataclass, asdict
  3. Date = str
  4. Url = str
  5. ContentType = str
  6. TweetId = str
  7. UserId = str
  8. MediaKey = str
  9. Error = Dict
  10. @dataclass
  11. class User:
  12. id: UserId
  13. username: Optional[str] = None
  14. created_at: Optional[Date] = None
  15. name: Optional[str] = None
  16. verified: Optional[bool] = None
  17. profile_image_url: Optional[Url] = None
  18. description: Optional[str] = None
  19. url: Optional[str] = None
  20. @dataclass
  21. class PublicMetrics:
  22. retweet_count: Optional[int] = None
  23. reply_count: Optional[int] = None
  24. like_count: Optional[int] = None
  25. quote_count: Optional[int] = None
  26. # on video media (only?)
  27. view_count: Optional[int] = None
  28. @dataclass
  29. class NonPublicMetrics:
  30. impression_count: Optional[int] = None
  31. profile_clicks: Optional[int] = None
  32. url_link_clicks: Optional[int] = None
  33. user_profile_clicks: Optional[int] = None
  34. @dataclass
  35. class Media:
  36. media_key: MediaKey
  37. type: str
  38. width: int
  39. height: int
  40. @dataclass
  41. class PhotoMedia(Media):
  42. url: Url
  43. @dataclass
  44. class VideoMediaVariant:
  45. content_type: ContentType
  46. url: Url
  47. bit_rate: Optional[int] = None
  48. @dataclass
  49. class VideoMedia (Media):
  50. preview_image_url: Url
  51. duration_ms: int
  52. variants: List[VideoMediaVariant]
  53. public_metrics: Optional[PublicMetrics] = None
  54. non_public_metrics: Optional[NonPublicMetrics] = None
  55. @dataclass
  56. class GifMedia (Media):
  57. preview_image_url: Url
  58. variants: List[VideoMediaVariant]
  59. public_metrics: Optional[PublicMetrics] = None
  60. non_public_metrics: Optional[NonPublicMetrics] = None
  61. @dataclass
  62. class TweetAttachments:
  63. media_keys: Optional[List[MediaKey]]
  64. @dataclass
  65. class MentionEntity:
  66. start: int
  67. end: int
  68. id: UserId
  69. username: str
  70. @dataclass
  71. class UrlEntity:
  72. start: int
  73. end: int
  74. url: Url
  75. expanded_url: Optional[Url] = None
  76. display_url: Optional[str] = None
  77. media_key: Optional[MediaKey] = None
  78. description: Optional[str] = None
  79. title: Optional[str] = None
  80. unwound_url: Optional[Url] = None
  81. status: Optional[int] = None
  82. @dataclass
  83. class TweetEntities:
  84. urls: Optional[List[UrlEntity]] = None
  85. mentions: Optional[List[MentionEntity]] = None
  86. @dataclass
  87. class ReferencedTweet:
  88. id: TweetId
  89. type: str
  90. @dataclass
  91. class Tweet:
  92. id: TweetId
  93. created_at: Date
  94. text: str
  95. conversation_id: Optional[TweetId] = None
  96. in_reply_to_tweet_id: Optional[TweetId] = None
  97. author_id: Optional[UserId] = None
  98. referenced_tweets: Optional[List[ReferencedTweet]] = None
  99. entities: Optional[TweetEntities] = None
  100. public_metrics: Optional[PublicMetrics] = None
  101. non_public_metrics: Optional[NonPublicMetrics] = None
  102. attachments: Optional[TweetAttachments] = None
  103. edit_history_tweet_ids: Optional[List[TweetId]] = None
  104. @dataclass
  105. class TweetExpansions:
  106. users: Optional[List[User]] = None
  107. media: Optional[List[Union[VideoMedia, PhotoMedia, GifMedia]]] = None
  108. tweets: Optional[List[Tweet]] = None
  109. @dataclass
  110. class TweetSearchMeta:
  111. count: Optional[int] = None # is this an error? different endpoint type?
  112. result_count: Optional[int] = None
  113. next_token: Optional[str] = None
  114. newest_id: Optional[TweetId] = None
  115. oldest_id: Optional[TweetId] = None
  116. @dataclass
  117. class TweetSearchResponse:
  118. data: Optional[List[Tweet]] = None
  119. meta: Optional[TweetSearchMeta] = None
  120. includes: Optional[TweetExpansions] = None
  121. errors: Optional[List[Error]] = None
  122. @dataclass
  123. class DMEvent:
  124. id: str
  125. created_at: str
  126. event_type: str
  127. dm_conversation_id: str
  128. @dataclass
  129. class DMCMessageCreate(DMEvent):
  130. sender_id: UserId
  131. text: str
  132. attachments: Optional[TweetAttachments] = None
  133. @dataclass
  134. class DMParticpantsJoin (DMEvent):
  135. participant_ids: List[UserId]
  136. @dataclass
  137. class DMParticpantsLeave (DMEvent):
  138. participant_ids: List[UserId]
  139. @dataclass
  140. class DMEventsResponse:
  141. data: List[Union[DMCMessageCreate, DMParticpantsJoin, DMParticpantsLeave]]
  142. meta: Optional[TweetSearchMeta] = None # is SearchResultsMeta a general response format?
  143. includes: Optional[TweetExpansions] = None
  144. UserSearchMeta = Dict
  145. @dataclass
  146. class UserSearchResponse:
  147. data: Optional[List[User]] = None
  148. meta: Optional[UserSearchMeta] = None
  149. includes: Optional[TweetExpansions] = None
  150. errors: Optional[List[Error]] = None