diff --git a/twikit/tweet.py b/twikit/tweet.py index 8682c863..b215093a 100644 --- a/twikit/tweet.py +++ b/twikit/tweet.py @@ -37,7 +37,7 @@ class Tweet: Indicates if the tweet is a quote status. quote : :class:`Tweet` The Tweet being quoted (if any) - retweeted : :class:`bool` + retweeted_tweet : :class:`bool` Whether the tweet is a retweet possibly_sensitive : :class:`bool` Indicates if the tweet content may be sensitive. @@ -77,6 +77,12 @@ class Tweet: Hashtags included in the tweet text. poll : :class:`Poll` Poll attached to the tweet. + has_card : :class:`bool` + Indicates if the tweet contains a card. + thumbnail_title : :class:`str` | None + The title of the webpage displayed inside tweet's card. + thumbnail_url : :class:`str` | None + Link to the image displayed in the tweet's card. """ def __init__(self, client: Client, data: dict, user: User = None) -> None: @@ -183,6 +189,35 @@ def __init__(self, client: Client, data: dict, user: User = None) -> None: else: self._poll_data = None + self.thumbnail_url = None + self.thumbnail_title = None + self.has_card = 'card' in data + if ( + 'card' in data and + 'legacy' in data['card'] and + 'binding_values' in data['card']['legacy'] + ): + card_data = data['card']['legacy']['binding_values'] + + if isinstance(card_data, list): + binding_values = { + i.get('key'): i.get('value') + for i in card_data + } + + if ( + 'title' in binding_values and + 'string_value' in binding_values['title'] + ): + self.thumbnail_title = binding_values['title']['string_value'] + + if ( + 'thumbnail_image_original' in binding_values and + 'image_value' in binding_values['thumbnail_image_original'] and + 'url' in binding_values['thumbnail_image_original']['image_value'] + ): + self.thumbnail_url = binding_values['thumbnail_image_original']['image_value']['url'] + @property def created_at_datetime(self) -> datetime: return timestamp_to_datetime(self.created_at) diff --git a/twikit/twikit_async/tweet.py b/twikit/twikit_async/tweet.py index 54bb5590..9c0dcd46 100644 --- a/twikit/twikit_async/tweet.py +++ b/twikit/twikit_async/tweet.py @@ -36,7 +36,7 @@ class Tweet: Indicates if the tweet is a quote status. quote : :class:`Tweet` The Tweet being quoted (if any) - retweeted : :class:`bool` + retweeted_tweet : :class:`bool` Whether the tweet is a retweet possibly_sensitive : :class:`bool` Indicates if the tweet content may be sensitive. @@ -74,6 +74,12 @@ class Tweet: Related tweets. hashtags: list[:class:`str`] Hashtags included in the tweet text. + has_card : :class:`bool` + Indicates if the tweet contains a card. + thumbnail_title : :class:`str` | None + The title of the webpage displayed inside tweet's card. + thumbnail_url : :class:`str` | None + Link to the image displayed in the tweet's card. """ def __init__(self, client: Client, data: dict, user: User = None) -> None: @@ -180,6 +186,35 @@ def __init__(self, client: Client, data: dict, user: User = None) -> None: else: self._poll_data = None + self.thumbnail_url = None + self.thumbnail_title = None + self.has_card = 'card' in data + if ( + 'card' in data and + 'legacy' in data['card'] and + 'binding_values' in data['card']['legacy'] + ): + card_data = data['card']['legacy']['binding_values'] + + if isinstance(card_data, list): + binding_values = { + i.get('key'): i.get('value') + for i in card_data + } + + if ( + 'title' in binding_values and + 'string_value' in binding_values['title'] + ): + self.thumbnail_title = binding_values['title']['string_value'] + + if ( + 'thumbnail_image_original' in binding_values and + 'image_value' in binding_values['thumbnail_image_original'] and + 'url' in binding_values['thumbnail_image_original']['image_value'] + ): + self.thumbnail_url = binding_values['thumbnail_image_original']['image_value']['url'] + @property def created_at_datetime(self) -> datetime: return timestamp_to_datetime(self.created_at)