twitter-openapi-python 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/PKG-INFO +2 -2
  2. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/pyproject.toml +2 -2
  3. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/pyproject.toml.orig +2 -2
  4. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/api/__init__.py +2 -0
  5. twitter_openapi_python-0.1.2/twitter_openapi_python/api/birdwatch_api.py +116 -0
  6. twitter_openapi_python-0.1.2/twitter_openapi_python/api/community_api.py +149 -0
  7. twitter_openapi_python-0.1.2/twitter_openapi_python/api/default_api.py +155 -0
  8. twitter_openapi_python-0.1.2/twitter_openapi_python/api/post_api.py +327 -0
  9. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/api/tweet_api.py +275 -21
  10. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/api/user_api.py +55 -1
  11. twitter_openapi_python-0.1.2/twitter_openapi_python/api/user_list_api.py +374 -0
  12. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/api/users_api.py +18 -0
  13. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/client.py +9 -1
  14. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/models/__init__.py +1 -0
  15. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/models/timeline.py +5 -0
  16. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/utils/__init__.py +7 -0
  17. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/utils/api.py +69 -8
  18. twitter_openapi_python-0.1.0/twitter_openapi_python/api/default_api.py +0 -80
  19. twitter_openapi_python-0.1.0/twitter_openapi_python/api/post_api.py +0 -166
  20. twitter_openapi_python-0.1.0/twitter_openapi_python/api/user_list_api.py +0 -171
  21. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/LICENSE +0 -0
  22. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/LICENSE.AGPL +0 -0
  23. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/README.md +0 -0
  24. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/__init__.py +0 -0
  25. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/api/initial_state_api.py +0 -0
  26. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/api/v11_get_api.py +0 -0
  27. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/api/v11_post_api.py +0 -0
  28. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/models/base.py +0 -0
  29. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/models/header.py +0 -0
  30. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/models/initial_state.py +0 -0
  31. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/models/response.py +0 -0
  32. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/py.typed +0 -0
  33. {twitter_openapi_python-0.1.0 → twitter_openapi_python-0.1.2}/twitter_openapi_python/tid.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter_openapi_python
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Twitter OpenAPI
5
5
  Keywords: twitter,api,python,scraper
6
6
  Author: fa0311
@@ -8,7 +8,7 @@ Author-email: fa0311 <yuki@yuki0311.com>
8
8
  License-Expression: LicenseRef-Custom OR AGPL-3.0-or-later
9
9
  License-File: LICENSE
10
10
  License-File: LICENSE.AGPL
11
- Requires-Dist: twitter-openapi-python-generated==0.1.0
11
+ Requires-Dist: twitter-openapi-python-generated==0.1.2
12
12
  Requires-Dist: pydantic>=2.6
13
13
  Requires-Dist: requests>=2.31.0,<3.0.0
14
14
  Requires-Dist: urllib3>=2.1.0,<3.0.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twitter_openapi_python"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "Twitter OpenAPI"
5
5
  readme = "README.md"
6
6
  license = "LicenseRef-Custom OR AGPL-3.0-or-later"
@@ -16,7 +16,7 @@ keywords = [
16
16
  ]
17
17
  requires-python = ">=3.10"
18
18
  dependencies = [
19
- "twitter_openapi_python_generated==0.1.0",
19
+ "twitter_openapi_python_generated==0.1.2",
20
20
  "pydantic>=2.6",
21
21
  "requests>=2.31.0,<3.0.0",
22
22
  "urllib3>=2.1.0,<3.0.0",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twitter_openapi_python"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "Twitter OpenAPI"
5
5
  authors = [{ name = "fa0311", email = "yuki@yuki0311.com" }]
6
6
  readme = "README.md"
@@ -9,7 +9,7 @@ license-files = ["LICENSE", "LICENSE.AGPL"]
9
9
  keywords = ["twitter", "api", "python", "scraper"]
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
- "twitter_openapi_python_generated==0.1.0",
12
+ "twitter_openapi_python_generated==0.1.2",
13
13
  "pydantic>=2.6",
14
14
  "requests>=2.31.0,<3.0.0",
15
15
  "urllib3>=2.1.0,<3.0.0",
@@ -2,6 +2,8 @@
2
2
 
3
3
  # flake8: noqa
4
4
 
5
+ from twitter_openapi_python.api.birdwatch_api import BirdwatchApiUtils
6
+ from twitter_openapi_python.api.community_api import CommunityApiUtils
5
7
  from twitter_openapi_python.api.default_api import DefaultApiUtils
6
8
  from twitter_openapi_python.api.initial_state_api import InitialStateApiUtils
7
9
  from twitter_openapi_python.api.post_api import PostApiUtils
@@ -0,0 +1,116 @@
1
+ from typing import Any, Optional
2
+
3
+ import twitter_openapi_python_generated as twitter
4
+ import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
6
+
7
+ from twitter_openapi_python.models import (
8
+ TimelineApiUtilsResponse,
9
+ TweetApiUtilsData,
10
+ TwitterApiUtilsResponse,
11
+ )
12
+ from twitter_openapi_python.utils import (
13
+ data_request,
14
+ error_check,
15
+ timeline_request,
16
+ tweet_entries_converter,
17
+ )
18
+
19
+ ResponseType = TwitterApiUtilsResponse[TimelineApiUtilsResponse[TweetApiUtilsData]]
20
+ ParamType = dict[str, Any]
21
+
22
+
23
+ class BirdwatchApiUtils:
24
+ """Community Notes."""
25
+
26
+ api: twitter.BirdwatchApi
27
+ flag: ParamType
28
+
29
+ def __init__(self, api: twitter.BirdwatchApi, flag: ParamType, ct: ClientTransaction):
30
+ self.api = api
31
+ self.flag = flag
32
+ self.ct = ct
33
+
34
+ def get_birdwatch_fetch_alias_self_select_status(
35
+ self,
36
+ extra_param: Optional[ParamType] = None,
37
+ ) -> TwitterApiUtilsResponse[models.BirdwatchAliasSelfSelectStatus]:
38
+ param: ParamType = {}
39
+ if extra_param is not None:
40
+ param.update(extra_param)
41
+ return data_request(
42
+ self.api.get_birdwatch_fetch_alias_self_select_status_with_http_info,
43
+ self.flag["BirdwatchFetchAliasSelfSelectStatus"],
44
+ self.ct,
45
+ lambda e: error_check(e.data, e.errors).authenticated_user_birdwatch_alias_self_select_status,
46
+ param,
47
+ )
48
+
49
+ def get_birdwatch_fetch_authenticated_user_profile(
50
+ self,
51
+ extra_param: Optional[ParamType] = None,
52
+ ) -> TwitterApiUtilsResponse[models.BirdwatchProfile]:
53
+ param: ParamType = {}
54
+ if extra_param is not None:
55
+ param.update(extra_param)
56
+ return data_request(
57
+ self.api.get_birdwatch_fetch_authenticated_user_profile_with_http_info,
58
+ self.flag["BirdwatchFetchAuthenticatedUserProfile"],
59
+ self.ct,
60
+ lambda e: error_check(e.data, e.errors).authenticated_user_birdwatch_profile,
61
+ param,
62
+ )
63
+
64
+ def get_birdwatch_fetch_birdwatch_profile(
65
+ self,
66
+ alias: str,
67
+ extra_param: Optional[ParamType] = None,
68
+ ) -> TwitterApiUtilsResponse[models.BirdwatchProfile]:
69
+ param: ParamType = {"alias": alias}
70
+ if extra_param is not None:
71
+ param.update(extra_param)
72
+ return data_request(
73
+ self.api.get_birdwatch_fetch_birdwatch_profile_with_http_info,
74
+ self.flag["BirdwatchFetchBirdwatchProfile"],
75
+ self.ct,
76
+ lambda e: error_check(e.data, e.errors).birdwatch_profile_by_alias,
77
+ param,
78
+ )
79
+
80
+ def get_birdwatch_fetch_global_timeline(
81
+ self,
82
+ cursor: Optional[str] = None,
83
+ extra_param: Optional[ParamType] = None,
84
+ ) -> ResponseType:
85
+ """Posts with notes on the Community Notes home page (first tab)."""
86
+ param: ParamType = {}
87
+ if cursor is not None:
88
+ param["cursor"] = cursor
89
+ if extra_param is not None:
90
+ param.update(extra_param)
91
+ return timeline_request(
92
+ self.api.get_birdwatch_fetch_global_timeline_with_http_info,
93
+ self.flag["BirdwatchFetchGlobalTimeline"],
94
+ self.ct,
95
+ lambda e: error_check(
96
+ e.data.viewer.birdwatch_home_page.body.initial_timeline.timeline.timeline, e.errors
97
+ ).instructions,
98
+ param,
99
+ tweet_entries_converter,
100
+ )
101
+
102
+ def get_birdwatch_fetch_public_data(
103
+ self,
104
+ extra_param: Optional[ParamType] = None,
105
+ ) -> TwitterApiUtilsResponse[models.BirdwatchPublicDataFileBundle]:
106
+ """Download urls of the latest public data files."""
107
+ param: ParamType = {}
108
+ if extra_param is not None:
109
+ param.update(extra_param)
110
+ return data_request(
111
+ self.api.get_birdwatch_fetch_public_data_with_http_info,
112
+ self.flag["BirdwatchFetchPublicData"],
113
+ self.ct,
114
+ lambda e: error_check(e.data, e.errors).birdwatch_latest_public_data_file_bundle,
115
+ param,
116
+ )
@@ -0,0 +1,149 @@
1
+ from typing import Any, List, Optional
2
+
3
+ import twitter_openapi_python_generated as twitter
4
+ import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
6
+
7
+ from twitter_openapi_python.models import (
8
+ TimelineApiUtilsResponse,
9
+ TweetApiUtilsData,
10
+ TwitterApiUtilsResponse,
11
+ )
12
+ from twitter_openapi_python.utils import (
13
+ data_request,
14
+ error_check,
15
+ timeline_request,
16
+ tweet_entries_converter,
17
+ )
18
+
19
+ ResponseType = TwitterApiUtilsResponse[TimelineApiUtilsResponse[TweetApiUtilsData]]
20
+ ParamType = dict[str, Any]
21
+
22
+
23
+ class CommunityApiUtils:
24
+ api: twitter.CommunityApi
25
+ flag: ParamType
26
+
27
+ def __init__(self, api: twitter.CommunityApi, flag: ParamType, ct: ClientTransaction):
28
+ self.api = api
29
+ self.flag = flag
30
+ self.ct = ct
31
+
32
+ def get_communities_fetch_one_query(
33
+ self,
34
+ community_id: str,
35
+ extra_param: Optional[ParamType] = None,
36
+ ) -> TwitterApiUtilsResponse[models.CommunityPageCommunity]:
37
+ """The community page (full members and moderators)."""
38
+ param: ParamType = {"communityId": community_id}
39
+ if extra_param is not None:
40
+ param.update(extra_param)
41
+ return data_request(
42
+ self.api.get_communities_fetch_one_query_with_http_info,
43
+ self.flag["CommunitiesFetchOneQuery"],
44
+ self.ct,
45
+ lambda e: error_check(e.data, e.errors).community_results.result,
46
+ param,
47
+ )
48
+
49
+ def get_community_query(
50
+ self,
51
+ community_id: str,
52
+ extra_param: Optional[ParamType] = None,
53
+ ) -> TwitterApiUtilsResponse[models.CommunitySettingsCommunity]:
54
+ """The community settings / moderation pages (partial users, trending hashtags)."""
55
+ param: ParamType = {"communityId": community_id}
56
+ if extra_param is not None:
57
+ param.update(extra_param)
58
+ return data_request(
59
+ self.api.get_community_query_with_http_info,
60
+ self.flag["CommunityQuery"],
61
+ self.ct,
62
+ lambda e: error_check(e.data, e.errors).community_results.result,
63
+ param,
64
+ )
65
+
66
+ def get_communities_search_query(
67
+ self,
68
+ query: str,
69
+ cursor: Optional[str] = None,
70
+ extra_param: Optional[ParamType] = None,
71
+ ) -> TwitterApiUtilsResponse[models.CommunitiesSearchSlice]:
72
+ """Community cards for a query; the next page is slice_info.next_cursor."""
73
+ param: ParamType = {"query": query}
74
+ if cursor is not None:
75
+ param["cursor"] = cursor
76
+ if extra_param is not None:
77
+ param.update(extra_param)
78
+ return data_request(
79
+ self.api.get_communities_search_query_with_http_info,
80
+ self.flag["CommunitiesSearchQuery"],
81
+ self.ct,
82
+ lambda e: error_check(e.data, e.errors).communities_search_slice,
83
+ param,
84
+ )
85
+
86
+ def get_topic_carousel_query(
87
+ self,
88
+ extra_param: Optional[ParamType] = None,
89
+ ) -> TwitterApiUtilsResponse[List[models.CommunityTopic]]:
90
+ param: ParamType = {}
91
+ if extra_param is not None:
92
+ param.update(extra_param)
93
+ return data_request(
94
+ self.api.get_topic_carousel_query_with_http_info,
95
+ self.flag["TopicCarouselQuery"],
96
+ self.ct,
97
+ lambda e: error_check(e.data, e.errors).community_topic_results.community_topics,
98
+ param,
99
+ )
100
+
101
+ def get_global_communities_post_search_timeline(
102
+ self,
103
+ raw_query: str,
104
+ cursor: Optional[str] = None,
105
+ count: Optional[int] = None,
106
+ extra_param: Optional[ParamType] = None,
107
+ ) -> ResponseType:
108
+ """Posts across communities (Top)."""
109
+ param: ParamType = {"rawQuery": raw_query}
110
+ if cursor is not None:
111
+ param["cursor"] = cursor
112
+ if count is not None:
113
+ param["count"] = count
114
+ if extra_param is not None:
115
+ param.update(extra_param)
116
+ return timeline_request(
117
+ self.api.get_global_communities_post_search_timeline_with_http_info,
118
+ self.flag["GlobalCommunitiesPostSearchTimeline"],
119
+ self.ct,
120
+ lambda e: error_check(e.data.search_by_raw_query.communities_posts_search_page.timeline, e.errors).instructions,
121
+ param,
122
+ tweet_entries_converter,
123
+ )
124
+
125
+ def get_global_communities_latest_post_search_timeline(
126
+ self,
127
+ raw_query: str,
128
+ cursor: Optional[str] = None,
129
+ count: Optional[int] = None,
130
+ extra_param: Optional[ParamType] = None,
131
+ ) -> ResponseType:
132
+ """Posts across communities (Latest)."""
133
+ param: ParamType = {"rawQuery": raw_query}
134
+ if cursor is not None:
135
+ param["cursor"] = cursor
136
+ if count is not None:
137
+ param["count"] = count
138
+ if extra_param is not None:
139
+ param.update(extra_param)
140
+ return timeline_request(
141
+ self.api.get_global_communities_latest_post_search_timeline_with_http_info,
142
+ self.flag["GlobalCommunitiesLatestPostSearchTimeline"],
143
+ self.ct,
144
+ lambda e: error_check(
145
+ e.data.search_by_raw_query.communities_latest_posts_search_page.timeline, e.errors
146
+ ).instructions,
147
+ param,
148
+ tweet_entries_converter,
149
+ )
@@ -0,0 +1,155 @@
1
+ from typing import Any, Callable, Optional, TypeVar
2
+
3
+ import twitter_openapi_python_generated as twitter
4
+ import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
6
+
7
+ from twitter_openapi_python.models import TweetApiUtilsData, TwitterApiUtilsResponse
8
+ from twitter_openapi_python.utils import (
9
+ build_response,
10
+ build_tweet_api_utils,
11
+ get_kwargs,
12
+ )
13
+ from twitter_openapi_python.utils.api import error_check
14
+
15
+ T1 = TypeVar("T1")
16
+ T2 = TypeVar("T2")
17
+ ApiFnType = Callable[..., twitter.ApiResponse[T1]]
18
+ ParamType = dict[str, Any]
19
+
20
+
21
+ class DefaultApiUtils:
22
+ api: twitter.DefaultApi
23
+ flag: ParamType
24
+
25
+ def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: ClientTransaction):
26
+ self.api = api
27
+ self.flag = flag
28
+ self.ct = ct
29
+
30
+ def request(
31
+ self,
32
+ apiFn: "ApiFnType[T1]",
33
+ convertFn: Callable[[T1], T2],
34
+ key: str,
35
+ param: ParamType,
36
+ ):
37
+ args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
38
+ res = apiFn(**args)
39
+ data = convertFn(res.data)
40
+ return build_response(res, data)
41
+
42
+ def get_profile_spotlights_query(
43
+ self,
44
+ screen_name: Optional[str] = None,
45
+ extra_param: Optional[ParamType] = None,
46
+ ) -> TwitterApiUtilsResponse[models.UserResultByScreenName]:
47
+ param: ParamType = {}
48
+ if screen_name is not None:
49
+ param["screen_name"] = screen_name
50
+ if extra_param is not None:
51
+ param.update(extra_param)
52
+
53
+ response = self.request(
54
+ apiFn=self.api.get_profile_spotlights_query_with_http_info,
55
+ convertFn=lambda x: error_check(x.data.user_result_by_screen_name, x.errors),
56
+ key="ProfileSpotlightsQuery",
57
+ param=param,
58
+ )
59
+ return response
60
+
61
+ def get_tweet_result_by_rest_id(
62
+ self,
63
+ tweet_id: str,
64
+ extra_param: Optional[ParamType] = None,
65
+ ) -> TwitterApiUtilsResponse[TweetApiUtilsData]:
66
+ param: ParamType = {"tweetId": tweet_id}
67
+ if extra_param is not None:
68
+ param.update(extra_param)
69
+
70
+ response = self.request(
71
+ apiFn=self.api.get_tweet_result_by_rest_id_with_http_info,
72
+ convertFn=lambda x: error_check(
73
+ build_tweet_api_utils(error_check(x.data.tweet_result, x.errors)), x.errors
74
+ ),
75
+ key="TweetResultByRestId",
76
+ param=param,
77
+ )
78
+ if response.data is None:
79
+ raise Exception("No tweet")
80
+ return response # type: ignore
81
+
82
+ def get_authenticate_periscope(
83
+ self,
84
+ extra_param: Optional[ParamType] = None,
85
+ ) -> TwitterApiUtilsResponse[str]:
86
+ """A Periscope (live video) token for the account."""
87
+ param: ParamType = {}
88
+ if extra_param is not None:
89
+ param.update(extra_param)
90
+ return self.request(
91
+ apiFn=self.api.get_authenticate_periscope_with_http_info,
92
+ convertFn=lambda x: error_check(x.data, x.errors).authenticate_periscope,
93
+ key="AuthenticatePeriscope",
94
+ param=param,
95
+ )
96
+
97
+ def get_creator_studio_tab_bar_item_query(
98
+ self,
99
+ extra_param: Optional[ParamType] = None,
100
+ ) -> TwitterApiUtilsResponse[models.CreatorStudioTabBarItemQueryResponseData]:
101
+ param: ParamType = {}
102
+ if extra_param is not None:
103
+ param.update(extra_param)
104
+ return self.request(
105
+ apiFn=self.api.get_creator_studio_tab_bar_item_query_with_http_info,
106
+ convertFn=lambda x: error_check(x.data, x.errors),
107
+ key="CreatorStudioTabBarItemQuery",
108
+ param=param,
109
+ )
110
+
111
+ def get_data_saver_mode(
112
+ self,
113
+ device_id: Optional[str] = None,
114
+ extra_param: Optional[ParamType] = None,
115
+ ) -> TwitterApiUtilsResponse[models.DataSaverModeResponseData]:
116
+ param: ParamType = {}
117
+ if device_id is not None:
118
+ param["device_id"] = device_id
119
+ if extra_param is not None:
120
+ param.update(extra_param)
121
+ return self.request(
122
+ apiFn=self.api.get_data_saver_mode_with_http_info,
123
+ convertFn=lambda x: error_check(x.data, x.errors),
124
+ key="DataSaverMode",
125
+ param=param,
126
+ )
127
+
128
+ def get_grok_home(
129
+ self,
130
+ extra_param: Optional[ParamType] = None,
131
+ ) -> TwitterApiUtilsResponse[models.GrokHome]:
132
+ """Grok model options, prompts and eligibility."""
133
+ param: ParamType = {}
134
+ if extra_param is not None:
135
+ param.update(extra_param)
136
+ return self.request(
137
+ apiFn=self.api.get_grok_home_with_http_info,
138
+ convertFn=lambda x: error_check(x.data, x.errors).grok_home,
139
+ key="GrokHome",
140
+ param=param,
141
+ )
142
+
143
+ def get_pinned_timelines(
144
+ self,
145
+ extra_param: Optional[ParamType] = None,
146
+ ) -> TwitterApiUtilsResponse[models.PinnedTimelines]:
147
+ param: ParamType = {}
148
+ if extra_param is not None:
149
+ param.update(extra_param)
150
+ return self.request(
151
+ apiFn=self.api.get_pinned_timelines_with_http_info,
152
+ convertFn=lambda x: error_check(x.data, x.errors).pinned_timelines,
153
+ key="PinnedTimelines",
154
+ param=param,
155
+ )