123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- from typing import List, Dict, Union, Optional
- from dataclasses import dataclass, asdict
- Date = str
- Url = str
- ContentType = str
- TweetId = str
- UserId = str
- MediaKey = str
- Error = Dict
- @dataclass
- class UserPublicMetrics:
- tweet_count: Optional[int] = None
- followers_count: Optional[int] = None
- following_count: Optional[int] = None
- listed_count: Optional[int] = None
- @dataclass
- class User:
- id: UserId
-
- username: Optional[str] = None
- created_at: Optional[Date] = None
- name: Optional[str] = None
- verified: Optional[bool] = None
- protected: Optional[bool] = None
- profile_image_url: Optional[Url] = None
- description: Optional[str] = None
- url: Optional[str] = None
- location: Optional[str] = None
-
- pinned_tweet_id: Optional[TweetId] = None
-
- public_metrics: Optional[UserPublicMetrics] = None
- @dataclass
- class PublicMetrics:
- retweet_count: Optional[int] = None
- reply_count: Optional[int] = None
- like_count: Optional[int] = None
- quote_count: Optional[int] = None
-
- # on video media (only?)
- view_count: Optional[int] = None
- @dataclass
- class NonPublicMetrics:
- impression_count: Optional[int] = None
- profile_clicks: Optional[int] = None
- url_link_clicks: Optional[int] = None
- user_profile_clicks: Optional[int] = None
-
- @dataclass
- class Media:
- media_key: MediaKey
- type: str
- width: int
- height: int
-
- @dataclass
- class PhotoMedia(Media):
- url: Url
-
- @dataclass
- class VideoMediaVariant:
- content_type: ContentType
- url: Url
- bit_rate: Optional[int] = None
- @dataclass
- class VideoMedia (Media):
- preview_image_url: Url
- duration_ms: int
- variants: List[VideoMediaVariant]
- public_metrics: Optional[PublicMetrics] = None
- non_public_metrics: Optional[NonPublicMetrics] = None
- @dataclass
- class GifMedia (Media):
- preview_image_url: Url
- variants: List[VideoMediaVariant]
- public_metrics: Optional[PublicMetrics] = None
- non_public_metrics: Optional[NonPublicMetrics] = None
- @dataclass
- class TweetAttachments:
- media_keys: Optional[List[MediaKey]]
- @dataclass
- class MentionEntity:
- start: int
- end: int
- id: UserId
- username: str
- @dataclass
- class UrlEntityImage:
- url: Url
- width: int
- height: int
- @dataclass
- class UrlEntity:
- start: int
- end: int
- url: Url
- expanded_url: Optional[Url] = None
- display_url: Optional[str] = None
- media_key: Optional[MediaKey] = None
- description: Optional[str] = None
- title: Optional[str] = None
- unwound_url: Optional[Url] = None
- status: Optional[int] = None
- images: Optional[List[UrlEntityImage]] = None
- @dataclass
- class TweetEntities:
- urls: Optional[List[UrlEntity]] = None
- mentions: Optional[List[MentionEntity]] = None
- @dataclass
- class ReferencedTweet:
- id: TweetId
- type: str
- @dataclass
- class Tweet:
- id: TweetId
- created_at: Date
- text: str
-
- conversation_id: Optional[TweetId] = None
- in_reply_to_tweet_id: Optional[TweetId] = None
- author_id: Optional[UserId] = None
- referenced_tweets: Optional[List[ReferencedTweet]] = None
- entities: Optional[TweetEntities] = None
- public_metrics: Optional[PublicMetrics] = None
- non_public_metrics: Optional[NonPublicMetrics] = None
- attachments: Optional[TweetAttachments] = None
- edit_history_tweet_ids: Optional[List[TweetId]] = None
- @dataclass
- class TweetExpansions:
- users: Optional[List[User]] = None
- media: Optional[List[Union[VideoMedia, PhotoMedia, GifMedia]]] = None
- tweets: Optional[List[Tweet]] = None
- @dataclass
- class TweetSearchMeta:
- count: Optional[int] = None # is this an error? different endpoint type?
- result_count: Optional[int] = None
- next_token: Optional[str] = None
- newest_id: Optional[TweetId] = None
- oldest_id: Optional[TweetId] = None
- @dataclass
- class TweetSearchResponse:
- data: Optional[List[Tweet]] = None
- meta: Optional[TweetSearchMeta] = None
- includes: Optional[TweetExpansions] = None
- errors: Optional[List[Error]] = None
- @dataclass
- class DMEvent:
- id: str
- created_at: str
- event_type: str
- dm_conversation_id: str
-
- @dataclass
- class DMCMessageCreate(DMEvent):
- sender_id: UserId
- text: str
- referenced_tweet_id: Optional[TweetId] = None
- attachments: Optional[TweetAttachments] = None
- @dataclass
- class DMParticpantsJoin (DMEvent):
- participant_ids: List[UserId]
-
- @dataclass
- class DMParticpantsLeave (DMEvent):
- participant_ids: List[UserId]
- @dataclass
- class DMEventsResponse:
- data: List[Union[DMCMessageCreate, DMParticpantsJoin, DMParticpantsLeave]]
- meta: Optional[TweetSearchMeta] = None # is SearchResultsMeta a general response format?
- includes: Optional[TweetExpansions] = None
- UserSearchMeta = Dict
- @dataclass
- class UserSearchResponse:
- data: Optional[List[User]] = None
- meta: Optional[UserSearchMeta] = None
- includes: Optional[TweetExpansions] = None
- errors: Optional[List[Error]] = None
|