types.py 4.9 KB

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