Skip to content

5. Models

Dev Jones edited this page Mar 25, 2024 · 6 revisions

In the models section of the PyTweetToolkit documentation, you'll find comprehensive details on the structure and usage of various data models representing Twitter entities like tweets, users, and media. These models are crucial for interacting with Twitter's API, encapsulating data in a structured manner.

List Model

Overview

The List model in PyTweetToolkit represents a Twitter List, providing a structured encapsulation of the list's details and metrics as returned by the Twitter API. This model is crucial for applications that interact with Twitter Lists, enabling easy access to their properties and associated metadata.

Attributes

  • created_at (str): The creation timestamp of the list.
  • custom_banner_media_url (str): URL for the custom banner image of the list, if available.
  • default_banner_media_url (str): URL for the default banner image.
  • description (str): Description of the list.
  • facepile_urls (list): Profile image URLs for users featured in the list.
  • is_following (bool): Indicates if the authenticated user follows this list.
  • id (int): Unique identifier of the list on Twitter.
  • rest_id (str): String representation of the list's ID.
  • is_member (bool): Indicates if the authenticated user is a member of this list.
  • member_count (int): Number of members in the list.
  • mode (str): Visibility mode of the list (e.g., "public" or "private").
  • muting (bool): Indicates if the list is muted.
  • name (str): Name of the list.
  • pinning (bool): Indicates if the list is pinned.
  • subscriber_count (int): Number of subscribers to the list.
  • owner (user_model.User): The owner of the list.

Methods

  • __str__() -> str Provides a human-readable string representation of the list, including key details such as ID, name, description, owner, and counts of members and subscribers.

  • to_dict() -> dict Converts the list model to a dictionary, facilitating serialization and API response generation. This method ensures that all list attributes are represented in a format suitable for data exchange or storage.

Notification Model

Overview

The Notification model within PyTweetToolkit provides a robust structure for representing Twitter notifications. It encapsulates the essential elements and contexts of notifications received from Twitter, such as mentions, follows, likes, retweets, and more. This model plays a vital role in processing and organizing notification data, making it accessible for applications to display or analyze notification events effectively.

Attributes

  • id (str): A unique identifier for the notification.
  • timestamp_ms (str): The time when the notification was created, represented in milliseconds.
  • icon (str): An identifier for the icon associated with the specific type of notification.
  • message (str): The textual content of the notification message.
  • tweet_ids (dict): Identifiers of tweets related to the notification.
  • user_ids (dict): Identifiers of users involved in the notification event.
  • additional_info (dict): Extra contextual information related to the notification.
  • tweet_details (list[tweet_model.Tweet]): A list containing Tweet objects that are associated with the notification, providing detailed context.

Methods

  • __str__() -> str Offers a human-readable summary of the notification, including its ID, message, and associated tweet details. This method is particularly useful for logging or debugging purposes.

  • to_dict() -> dict Transforms the notification into a dictionary format, facilitating easy serialization or API response generation. This method ensures that the notification's properties, along with the detailed tweet contexts, are systematically represented for further processing or storage.

Tweet Model

Overview

The Tweet model in PyTweetToolkit serves as a comprehensive representation of a Twitter post. It encapsulates all relevant data about a tweet, including content, authorship, interaction metrics, media attachments, and the context of replies, quotes, and retweets. This model facilitates the manipulation and display of tweet data, making it essential for applications integrating Twitter functionality.

Attributes

  • rest_id: Unique identifier for the tweet.
  • user: The author of the tweet, represented as a user_model.User instance.
  • edit_tweet_ids: IDs of the tweet's edit history.
  • editable_until_msecs: Timestamp until the tweet is editable.
  • is_edit_eligible: Eligibility of the tweet for editing.
  • edits_remaining: Number of remaining edits for the tweet.
  • is_translatable: Whether the tweet can be translated.
  • views: View count of the tweet.
  • quoted_tweet: The tweet being quoted, if applicable.
  • bookmark_count: Number of bookmarks for the tweet.
  • bookmarked: Whether the tweet is bookmarked by the current user.
  • created_at: Creation time of the tweet.
  • hashtags: Hashtags mentioned in the tweet.
  • symbols: Symbols (e.g., stock tickers) mentioned.
  • timestamps: Timestamps mentioned in the tweet.
  • urls: URLs included in the tweet.
  • user_mentions: User mentions in the tweet.
  • media: Media items attached to the tweet.
  • favorite_count: Number of likes for the tweet.
  • favorited: Whether the tweet is liked by the current user.
  • full_text: The full text of the tweet.
  • in_reply_to_screen_name: The screen name to whom the tweet replies.
  • in_reply_to_tweet_id_str: The tweet ID to which this tweet replies.
  • in_reply_to_user_id_str: The user ID to whom the tweet replies.
  • is_reply: Indicates if the tweet is a reply.
  • is_quote_tweet: Indicates if the tweet is a quote.
  • quoted_tweet_id_str: ID of the quoted tweet.
  • quoted_tweet_permalink: Permalink of the quoted tweet.
  • lang: Language code of the tweet.
  • possibly_sensitive: If the tweet may contain sensitive content.
  • possibly_sensitive_editable: If the tweet's sensitivity label can be edited.
  • quote_count: Number of quotes of the tweet.
  • reply_count: Number of replies to the tweet.
  • retweet_count: Number of retweets.
  • retweeted: Whether the tweet is retweeted by the current user.
  • retweeted_tweet: The original tweet if this is a retweet.

Methods

  • __str__() -> str Returns a string representation of the tweet, summarizing essential details such as the author, content, and interaction metrics.

  • to_dict() -> dict Converts the tweet and its associated data into a dictionary format. This includes transforming nested objects like the author (user), quoted tweet (quoted_tweet), and retweeted tweet (retweeted_tweet) into dictionaries, facilitating integration with APIs or data storage solutions.

User Model

Overview

The User model in PyTweetToolkit encapsulates comprehensive information about a Twitter user's profile. This model serves as a detailed representation of a user's identity on Twitter, including both personal attributes and engagement metrics. It covers a wide array of information, from basic profile details such as name and description to intricate metrics like follower counts and tweet engagement. This model is essential for applications that require a deep understanding of user profiles on Twitter.

Attributes

  • id and rest_id: Unique identifiers for the user, facilitating API interactions.
  • is_blue_verified: Verification status of the user, indicating a verified blue checkmark.
  • profile_image_shape: Shape of the profile image, enhancing UI/UX design.
  • can_dm and can_media_tag: Permissions for direct messaging and media tagging.
  • created_at: Account creation timestamp, useful for age analysis.
  • default_profile and default_profile_image: Indicators for default settings usage.
  • description: Self-description, providing insight into personal or professional interests.
  • fast_followers_count and normal_followers_count: Follower metrics for engagement analysis.
  • favourites_count, followers_count, friends_count, and listed_count: Engagement and network size indicators.
  • has_custom_timelines and is_translator: Special roles and capabilities of the user.
  • location, media_count, and statuses_count: Geographical, media, and activity metrics.
  • name and screen_name: Basic identity markers.
  • pinned_tweet_ids_str: Highlighted content, indicating user priorities or interests.
  • possibly_sensitive: Content sensitivity flag, impacting visibility and reach.
  • profile_banner_url and profile_image_url_https: Visual elements of the profile.
  • verified: Overall verification status.
  • withheld_in_countries: Content restriction metrics.
  • professional_rest_id, professional_type, and professional_category: Professional identity indicators.
  • verified_phone_status: Phone verification status, enhancing account security.
  • legacy_extended_profile: Additional profile details for legacy support.
  • is_profile_translatable: Translation capability, expanding global reach.
  • has_hidden_likes_on_profile and has_hidden_subscriptions_on_profile: Privacy settings.
  • is_identity_verified and can_highlight_tweets: Identity verification and content highlighting capabilities.
  • highlighted_tweets: Specific content highlighted by the user.

Methods

  • __str__() -> str Returns a concise, human-readable summary of the user profile, including key identifiers, profile details, and selected metrics. This is useful for logging, debugging, and user-friendly displays.

  • to_dict() -> dict Transforms the User instance into a dictionary format. This method is particularly useful for serializing the user data for storage, network transmission, or integration with other systems. It ensures all user attributes are organized and accessible in a structured format.

Clone this wiki locally