Add constants for potential model object fields
authorHarmon <Harmon758@gmail.com>
Sat, 18 Mar 2023 11:26:29 +0000 (06:26 -0500)
committerHarmon <Harmon758@gmail.com>
Sat, 18 Mar 2023 11:26:29 +0000 (06:26 -0500)
docs/expansions_and_fields.rst
tweepy/__init__.py
tweepy/direct_message_event.py
tweepy/list.py
tweepy/media.py
tweepy/place.py
tweepy/poll.py
tweepy/space.py
tweepy/tweet.py
tweepy/user.py

index 6c38e1671e7864226ddcd8d6d7298359823e86ff..76b0fcab0ed29fea5e4f48799d306c83aa39d8c5 100644 (file)
@@ -269,3 +269,32 @@ user data objects.
 .. _Space fields: https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/space
 .. _Tweet fields: https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/tweet
 .. _user fields: https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user
+
+Constants
+---------
+
+These constants are available directly in the :mod:`tweepy` module, which means
+each file itself does not need to be imported. For example,
+:const:`tweepy.user.USER_FIELDS` is available as :const:`tweepy.USER_FIELDS`.
+
+.. autodata:: tweepy.direct_message_event.DIRECT_MESSAGE_EVENT_FIELDS
+
+.. autodata:: tweepy.direct_message_event.DM_EVENT_FIELDS
+
+.. autodata:: tweepy.list.LIST_FIELDS
+
+.. autodata:: tweepy.media.MEDIA_FIELDS
+
+.. autodata:: tweepy.place.PLACE_FIELDS
+
+.. autodata:: tweepy.poll.POLL_FIELDS
+
+.. autodata:: tweepy.space.PUBLIC_SPACE_FIELDS
+
+.. autodata:: tweepy.space.SPACE_FIELDS
+
+.. autodata:: tweepy.tweet.PUBLIC_TWEET_FIELDS
+
+.. autodata:: tweepy.tweet.TWEET_FIELDS
+
+.. autodata:: tweepy.user.USER_FIELDS
index 8c912503a21f6596365afa76e809bd091c0ffd8d..90bdda8e0b748cf7fefb5c5ae5f4e000b551e60c 100644 (file)
@@ -17,22 +17,26 @@ from tweepy.auth import (
 from tweepy.cache import Cache, FileCache, MemoryCache
 from tweepy.client import Client, Response
 from tweepy.cursor import Cursor
-from tweepy.direct_message_event import DirectMessageEvent
+from tweepy.direct_message_event import (
+    DirectMessageEvent, DIRECT_MESSAGE_EVENT_FIELDS, DM_EVENT_FIELDS
+)
 from tweepy.errors import (
     BadRequest, Forbidden, HTTPException, NotFound, TooManyRequests,
     TweepyException, TwitterServerError, Unauthorized
 )
-from tweepy.list import List
-from tweepy.media import Media
+from tweepy.list import List, LIST_FIELDS
+from tweepy.media import Media, MEDIA_FIELDS
 from tweepy.pagination import Paginator
-from tweepy.place import Place
-from tweepy.poll import Poll
-from tweepy.space import Space
+from tweepy.place import Place, PLACE_FIELDS
+from tweepy.poll import Poll, POLL_FIELDS
+from tweepy.space import PUBLIC_SPACE_FIELDS, Space, SPACE_FIELDS
 from tweepy.streaming import (
     StreamingClient, StreamResponse, StreamRule
 )
-from tweepy.tweet import ReferencedTweet, Tweet
-from tweepy.user import User
+from tweepy.tweet import (
+    PUBLIC_TWEET_FIELDS, ReferencedTweet, Tweet, TWEET_FIELDS
+)
+from tweepy.user import User, USER_FIELDS
 
 # Global, unauthenticated instance of API
 api = API()
index 882c62c41783ebfa48821d130161b441c2814f85..acac5589726c7e656c493ef2811f18762f051fdf 100644 (file)
@@ -7,6 +7,22 @@ from tweepy.tweet import ReferencedTweet
 from tweepy.utils import parse_datetime
 
 
+#: All the potential fields for :class:`DirectMessageEvent` objects
+DIRECT_MESSAGE_EVENT_FIELDS = [
+    "attachments",
+    "created_at",
+    "dm_conversation_id",
+    "event_type",
+    "id",
+    "participant_ids",
+    "referenced_tweets",
+    "sender_id",
+    "text",
+]
+#: Alias for :const:`DIRECT_MESSAGE_EVENT_FIELDS`
+DM_EVENT_FIELDS = DIRECT_MESSAGE_EVENT_FIELDS
+
+
 class DirectMessageEvent(HashableID, DataMapping):
     """Direct Message (DM) conversations are made up of events. The Twitter API
     v2 currently supports three event types: MessageCreate, ParticipantsJoin,
index ad54605bf64231b9ab9950611ca10432fae1191b..1db957bddddf3b10390e2e4007069d3c86b43e0f 100644 (file)
@@ -6,6 +6,19 @@ from tweepy.mixins import DataMapping, HashableID
 from tweepy.utils import parse_datetime
 
 
+#: All the potential fields for :class:`List` objects
+LIST_FIELDS = [
+    "created_at",
+    "description",
+    "follower_count",
+    "id",
+    "member_count",
+    "name",
+    "owner_id",
+    "private",
+]
+
+
 class List(HashableID, DataMapping):
     """The list object contains `Twitter Lists`_ metadata describing the
     referenced List. The List object is the primary object returned in the List
index d6c7f7e27f9948cdd8c40ffafb6623aa2561639b..1c7b48a669e55e9af289b0e8a8f108d2d4af9344 100644 (file)
@@ -5,6 +5,24 @@
 from tweepy.mixins import DataMapping
 
 
+#: All the potential fields for :class:`Media` objects
+MEDIA_FIELDS = [
+    "alt_text",
+    "duration_ms",
+    "height",
+    "media_key",
+    "non_public_metrics",
+    "organic_metrics",
+    "preview_image_url",
+    "promoted_metrics",
+    "public_metrics",
+    "type",
+    "url",
+    "variants",
+    "width",
+]
+
+
 class Media(DataMapping):
     """Media refers to any image, GIF, or video attached to a Tweet. The media
     object is not a primary object on any endpoint, but can be found and
index c51b1be4488aff711116d387a9866f85a11949d4..c1e83522f30c4d31ce01d5974b6fb2e59895a53a 100644 (file)
@@ -5,6 +5,19 @@
 from tweepy.mixins import DataMapping, HashableID
 
 
+#: All the potential fields for :class:`Place` objects
+PLACE_FIELDS = [
+    "contained_within",
+    "country",
+    "country_code",
+    "full_name",
+    "geo",
+    "id",
+    "name",
+    "place_type",
+]
+
+
 class Place(HashableID, DataMapping):
     """The place tagged in a Tweet is not a primary object on any endpoint, but
     can be found and expanded in the Tweet resource. 
index 6bb4bd3ce859e006c04dc0c5ad12e31bf4d67ec3..62ce160b961a6ccc1a341bd6e6c9c8a5914dcb0a 100644 (file)
@@ -6,6 +6,16 @@ from tweepy.mixins import DataMapping, HashableID
 from tweepy.utils import parse_datetime
 
 
+#: All the potential fields for :class:`Poll` objects
+POLL_FIELDS = [
+    "duration_minutes",
+    "end_datetime",
+    "id",
+    "options",
+    "voting_status",
+]
+
+
 class Poll(HashableID, DataMapping):
     """A poll included in a Tweet is not a primary object on any endpoint, but
     can be found and expanded in the Tweet object. 
index 128630ca15abfd2e6c2025293c9ac90b5fb3c8fb..17fe227e8b5a7cd113cc5cf05640feb17ad9d89f 100644 (file)
@@ -6,6 +6,32 @@ from tweepy.mixins import DataMapping, HashableID
 from tweepy.utils import parse_datetime
 
 
+#: All the potential publically-available fields for :class:`Space` objects
+PUBLIC_SPACE_FIELDS = [
+    "created_at",
+    "creator_id",
+    "ended_at",
+    "host_ids",
+    "id",
+    "invited_user_ids",
+    "is_ticketed",
+    "lang",
+    "participant_count",
+    "scheduled_start",
+    "speaker_ids",
+    "started_at",
+    "state",
+    "title",
+    "topic_ids",
+    "updated_at",
+]
+
+#: All the potential fields for :class:`Space` objects
+SPACE_FIELDS = PUBLIC_SPACE_FIELDS + [
+    "subscriber_count",
+]
+
+
 class Space(HashableID, DataMapping):
     """Spaces allow expression and interaction via live audio conversations.
     The Space data dictionary contains relevant metadata about a Space; all the
index 3f04e30f6a9bf7f8c759ddd69ff5c0d04df75d23..e6947d10d007c4b6ae5bf5bf8de4358b8059b831 100644 (file)
@@ -8,6 +8,37 @@ from tweepy.mixins import DataMapping, HashableID
 from tweepy.utils import parse_datetime
 
 
+#: All the potential publically-available fields for :class:`Tweet` objects
+PUBLIC_TWEET_FIELDS = [
+    "attachments",
+    "author_id",
+    "context_annotations",
+    "conversation_id",
+    "created_at",
+    "edit_controls",
+    "edit_history_tweet_ids",
+    "entities",
+    "geo",
+    "id",
+    "in_reply_to_user_id",
+    "lang",
+    "possibly_sensitive",
+    "public_metrics",
+    "referenced_tweets",
+    "reply_settings",
+    "source",
+    "text",
+    "withheld",
+]
+
+#: All the potential fields for :class:`Tweet` objects
+TWEET_FIELDS = PUBLIC_TWEET_FIELDS + [
+    "non_public_metrics",
+    "organic_metrics",
+    "promoted_metrics",
+]
+
+
 class Tweet(HashableID, DataMapping):
     """Tweets are the basic building block of all things Twitter. The Tweet
     object has a long list of ‘root-level’ fields, such as ``id``, ``text``,
index 2ebceca9ca4162bd1ae831863fb2d15eec8e1621..31d9e9de7136355e5223ce1326ca4c5f0f9a9579 100644 (file)
@@ -6,6 +6,26 @@ from tweepy.mixins import DataMapping, HashableID
 from tweepy.utils import parse_datetime
 
 
+#: All the potential fields for :class:`User` objects
+USER_FIELDS = [
+    "created_at",
+    "description",
+    "entities",
+    "id",
+    "location",
+    "name",
+    "pinned_tweet_id",
+    "profile_image_url",
+    "protected",
+    "public_metrics",
+    "url",
+    "username",
+    "verified",
+    "verified_type",
+    "withheld",
+]
+
+
 class User(HashableID, DataMapping):
     """The user object contains Twitter user account metadata describing the
     referenced user. The user object is the primary object returned in the