types.py 5.0 KB

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