twitter-openapi-python 0.0.35__tar.gz → 0.0.37__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 (35) hide show
  1. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/PKG-INFO +1 -1
  2. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/pyproject.toml +2 -2
  3. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/setup.py +2 -6
  4. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/default_api.py +4 -2
  5. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/post_api.py +10 -1
  6. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/tweet_api.py +61 -8
  7. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/user_api.py +4 -2
  8. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/user_list_api.py +4 -2
  9. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/users_api.py +4 -2
  10. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/client.py +15 -11
  11. twitter_openapi_python-0.0.37/twitter_openapi_python/tid.py +17 -0
  12. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/utils/api.py +9 -1
  13. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python.egg-info/PKG-INFO +1 -1
  14. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python.egg-info/SOURCES.txt +1 -0
  15. twitter_openapi_python-0.0.37/twitter_openapi_python.egg-info/requires.txt +3 -0
  16. twitter_openapi_python-0.0.35/twitter_openapi_python.egg-info/requires.txt +0 -3
  17. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/LICENSE +0 -0
  18. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/LICENSE.AGPL +0 -0
  19. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/README.md +0 -0
  20. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/setup.cfg +0 -0
  21. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/__init__.py +0 -0
  22. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/__init__.py +0 -0
  23. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/initial_state_api.py +0 -0
  24. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/v11_get_api.py +0 -0
  25. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/api/v11_post_api.py +0 -0
  26. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/models/__init__.py +0 -0
  27. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/models/base.py +0 -0
  28. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/models/header.py +0 -0
  29. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/models/initial_state.py +0 -0
  30. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/models/response.py +0 -0
  31. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/models/timeline.py +0 -0
  32. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/py.typed +0 -0
  33. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python/utils/__init__.py +0 -0
  34. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python.egg-info/dependency_links.txt +0 -0
  35. {twitter_openapi_python-0.0.35 → twitter_openapi_python-0.0.37}/twitter_openapi_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: twitter_openapi_python
3
- Version: 0.0.35
3
+ Version: 0.0.37
4
4
  Summary: Twitter OpenAPI
5
5
  Home-page: https://github.com/fa0311/twitter_openapi_python
6
6
  Author: fa0311
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "twitter_openapi_python"
3
- version = "0.0.35"
3
+ version = "0.0.37"
4
4
  description = "Twitter OpenAPI"
5
5
  authors = ["fa0311 <yuki@yuki0311.com>"]
6
6
  license = "proprietary" # or "AGPL-3.0-only"
@@ -15,7 +15,7 @@ python = "^3.7"
15
15
  pydantic = ">=2.6"
16
16
  urllib3 = ">= 2.1.0 < 3.0.0"
17
17
 
18
- twitter-openapi-python-generated = "0.0.31"
18
+ twitter-openapi-python-generated = "0.0.33"
19
19
 
20
20
  [tool.poetry.dev-dependencies]
21
21
 
@@ -5,13 +5,9 @@ import re
5
5
  from setuptools import find_packages, setup
6
6
 
7
7
  NAME = "twitter_openapi_python"
8
- VERSION = "0.0.35"
8
+ VERSION = "0.0.37"
9
9
  PYTHON_REQUIRES = ">=3.7"
10
- REQUIRES = [
11
- "twitter_openapi_python_generated == 0.0.31",
12
- "pydantic >= 2.6",
13
- "urllib3 >= 2.1.0, < 3.0.0"
14
- ]
10
+ REQUIRES = ["twitter_openapi_python_generated == 0.0.33", "pydantic >= 2.6", "urllib3 >= 2.1.0, < 3.0.0"]
15
11
  GITHUB_RAW_URL = (
16
12
  "https://raw.githubusercontent.com/fa0311/twitter_openapi_python/refs/heads/master/twitter_openapi_python/"
17
13
  )
@@ -2,6 +2,7 @@ from typing import Any, Callable, Optional, TypeVar
2
2
 
3
3
  import twitter_openapi_python_generated as twitter
4
4
  import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
5
6
 
6
7
  from twitter_openapi_python.models import TweetApiUtilsData, TwitterApiUtilsResponse
7
8
  from twitter_openapi_python.utils import (
@@ -21,9 +22,10 @@ class DefaultApiUtils:
21
22
  api: twitter.DefaultApi
22
23
  flag: ParamType
23
24
 
24
- def __init__(self, api: twitter.DefaultApi, flag: ParamType):
25
+ def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: ClientTransaction):
25
26
  self.api = api
26
27
  self.flag = flag
28
+ self.ct = ct
27
29
 
28
30
  def request(
29
31
  self,
@@ -32,7 +34,7 @@ class DefaultApiUtils:
32
34
  key: str,
33
35
  param: ParamType,
34
36
  ):
35
- args = get_kwargs(flag=self.flag[key], additional=param)
37
+ args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
36
38
  res = apiFn(**args)
37
39
  data = convertFn(res.data)
38
40
  return build_response(res, data)
@@ -2,9 +2,11 @@ from typing import Any, Optional, TypeVar
2
2
 
3
3
  import twitter_openapi_python_generated as twitter
4
4
  import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
5
6
 
6
7
  from twitter_openapi_python.models import TwitterApiUtilsResponse
7
8
  from twitter_openapi_python.utils import build_response, non_nullable
9
+ from twitter_openapi_python.utils.api import get_headers
8
10
 
9
11
  T = TypeVar("T")
10
12
  ResponseType = TwitterApiUtilsResponse[T]
@@ -15,9 +17,10 @@ class PostApiUtils:
15
17
  api: twitter.PostApi
16
18
  flag: ParamType
17
19
 
18
- def __init__(self, api: twitter.PostApi, flag: ParamType):
20
+ def __init__(self, api: twitter.PostApi, flag: ParamType, ct: ClientTransaction):
19
21
  self.api = api
20
22
  self.flag = flag
23
+ self.ct = ct
21
24
 
22
25
  def post_create_tweet(
23
26
  self,
@@ -61,6 +64,7 @@ class PostApiUtils:
61
64
  variables=variables,
62
65
  features=features,
63
66
  ),
67
+ _headers=get_headers(self.flag["CreateTweet"], self.ct),
64
68
  )
65
69
  return build_response(res, res.data)
66
70
 
@@ -79,6 +83,7 @@ class PostApiUtils:
79
83
  queryId=self.flag["DeleteTweet"]["queryId"],
80
84
  variables=variables,
81
85
  ),
86
+ _headers=get_headers(self.flag["DeleteTweet"], self.ct),
82
87
  )
83
88
  return build_response(res, res.data)
84
89
 
@@ -97,6 +102,7 @@ class PostApiUtils:
97
102
  queryId=self.flag["CreateRetweet"]["queryId"],
98
103
  variables=variables,
99
104
  ),
105
+ _headers=get_headers(self.flag["CreateRetweet"], self.ct),
100
106
  )
101
107
  return build_response(res, res.data)
102
108
 
@@ -115,6 +121,7 @@ class PostApiUtils:
115
121
  queryId=self.flag["DeleteRetweet"]["queryId"],
116
122
  variables=variables,
117
123
  ),
124
+ _headers=get_headers(self.flag["DeleteRetweet"], self.ct),
118
125
  )
119
126
  return build_response(res, res.data)
120
127
 
@@ -134,6 +141,7 @@ class PostApiUtils:
134
141
  queryId=self.flag["FavoriteTweet"]["queryId"],
135
142
  variables=variables,
136
143
  ),
144
+ _headers=get_headers(self.flag["FavoriteTweet"], self.ct),
137
145
  )
138
146
  return build_response(res, res.data)
139
147
 
@@ -153,5 +161,6 @@ class PostApiUtils:
153
161
  queryId=self.flag["UnfavoriteTweet"]["queryId"],
154
162
  variables=variables,
155
163
  ),
164
+ _headers=get_headers(self.flag["UnfavoriteTweet"], self.ct),
156
165
  )
157
166
  return build_response(res, res.data)
@@ -1,7 +1,8 @@
1
- from typing import Any, Callable, List, Optional, TypeVar
1
+ from typing import Any, Callable, List, Literal, Optional, TypeVar
2
2
 
3
3
  import twitter_openapi_python_generated as twitter
4
4
  import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
5
6
 
6
7
  from twitter_openapi_python.models import (
7
8
  ApiUtilsRaw,
@@ -28,9 +29,10 @@ class TweetApiUtils:
28
29
  api: twitter.TweetApi
29
30
  flag: ParamType
30
31
 
31
- def __init__(self, api: twitter.TweetApi, flag: ParamType):
32
+ def __init__(self, api: twitter.TweetApi, flag: ParamType, ct: ClientTransaction):
32
33
  self.api = api
33
34
  self.flag = flag
35
+ self.ct = ct
34
36
 
35
37
  def request(
36
38
  self,
@@ -39,7 +41,7 @@ class TweetApiUtils:
39
41
  key: str,
40
42
  param: ParamType,
41
43
  ) -> ResponseType:
42
- args = get_kwargs(flag=self.flag[key], additional=param)
44
+ args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
43
45
  res = apiFn(**args)
44
46
  instruction = convertFn(res.data)
45
47
  entry = instruction_to_entry(instruction)
@@ -81,7 +83,7 @@ class TweetApiUtils:
81
83
  def get_search_timeline(
82
84
  self,
83
85
  raw_query: str,
84
- product: Optional[str] = None,
86
+ product: Optional[Literal["Top", "Latest", "People", "Photos", "Videos"]] = None,
85
87
  cursor: Optional[str] = None,
86
88
  count: Optional[int] = None,
87
89
  extra_param: Optional[ParamType] = None,
@@ -191,7 +193,7 @@ class TweetApiUtils:
191
193
  response = self.request(
192
194
  apiFn=self.api.get_user_tweets_with_http_info,
193
195
  convertFn=lambda e: error_check(
194
- error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
196
+ error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
195
197
  ).instructions,
196
198
  key="UserTweets",
197
199
  param=param,
@@ -216,7 +218,7 @@ class TweetApiUtils:
216
218
  response = self.request(
217
219
  apiFn=self.api.get_user_tweets_and_replies_with_http_info,
218
220
  convertFn=lambda e: error_check(
219
- error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
221
+ error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
220
222
  ).instructions,
221
223
  key="UserTweetsAndReplies",
222
224
  param=param,
@@ -241,7 +243,7 @@ class TweetApiUtils:
241
243
  response = self.request(
242
244
  apiFn=self.api.get_user_media_with_http_info,
243
245
  convertFn=lambda e: error_check(
244
- error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
246
+ error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
245
247
  ).instructions,
246
248
  key="UserMedia",
247
249
  param=param,
@@ -266,7 +268,7 @@ class TweetApiUtils:
266
268
  response = self.request(
267
269
  apiFn=self.api.get_likes_with_http_info,
268
270
  convertFn=lambda e: error_check(
269
- error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
271
+ error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
270
272
  ).instructions,
271
273
  key="Likes",
272
274
  param=param,
@@ -296,3 +298,54 @@ class TweetApiUtils:
296
298
  param=param,
297
299
  )
298
300
  return response
301
+
302
+ def get_community_tweets_timeline(
303
+ self,
304
+ cursor: Optional[str] = None,
305
+ count: Optional[int] = None,
306
+ rankingMode: Optional[Literal["Recency", "Relevance"]] = None,
307
+ extra_param: Optional[ParamType] = None,
308
+ ) -> ResponseType:
309
+ param: ParamType = {}
310
+ if cursor is not None:
311
+ param["cursor"] = cursor
312
+ if count is not None:
313
+ param["count"] = count
314
+ if rankingMode is not None:
315
+ param["rankingMode"] = rankingMode
316
+ if extra_param is not None:
317
+ param.update(extra_param)
318
+
319
+ response = self.request(
320
+ apiFn=self.api.get_community_tweets_timeline_with_http_info,
321
+ convertFn=lambda e: error_check(
322
+ error_check(e.data, e.errors).community_results.result.ranked_community_timeline.timeline, e.errors
323
+ ).instructions,
324
+ key="CommunityTweetsTimeline",
325
+ param=param,
326
+ )
327
+ return response
328
+
329
+ def get_community_media_timeline(
330
+ self,
331
+ cursor: Optional[str] = None,
332
+ count: Optional[int] = None,
333
+ extra_param: Optional[ParamType] = None,
334
+ ) -> ResponseType:
335
+ param: ParamType = {}
336
+ if cursor is not None:
337
+ param["cursor"] = cursor
338
+ if count is not None:
339
+ param["count"] = count
340
+ if extra_param is not None:
341
+ param.update(extra_param)
342
+
343
+ response = self.request(
344
+ apiFn=self.api.get_community_media_timeline_with_http_info,
345
+ convertFn=lambda e: error_check(
346
+ error_check(e.data, e.errors).community_results.result.community_media_timeline.timeline, e.errors
347
+ ).instructions,
348
+ key="CommunityMediaTimeline",
349
+ param=param,
350
+ )
351
+ return response
@@ -2,6 +2,7 @@ from typing import Any, Callable, Optional, TypeVar
2
2
 
3
3
  import twitter_openapi_python_generated as twitter
4
4
  import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
5
6
 
6
7
  from twitter_openapi_python.models import TwitterApiUtilsResponse, UserApiUtilsData
7
8
  from twitter_openapi_python.utils import (
@@ -21,9 +22,10 @@ class UserApiUtils:
21
22
  api: twitter.UserApi
22
23
  flag: ParamType
23
24
 
24
- def __init__(self, api: twitter.UserApi, flag: ParamType):
25
+ def __init__(self, api: twitter.UserApi, flag: ParamType, ct: ClientTransaction):
25
26
  self.api = api
26
27
  self.flag = flag
28
+ self.ct = ct
27
29
 
28
30
  def request(
29
31
  self,
@@ -32,7 +34,7 @@ class UserApiUtils:
32
34
  key: str,
33
35
  param: ParamType,
34
36
  ) -> ResponseType:
35
- args = get_kwargs(flag=self.flag[key], additional=param)
37
+ args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
36
38
  res = apiFn(**args)
37
39
  result = convertFn(res.data)
38
40
  if result.result is None:
@@ -2,6 +2,7 @@ from typing import Any, Callable, List, Optional, TypeVar
2
2
 
3
3
  import twitter_openapi_python_generated as twitter
4
4
  import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
5
6
 
6
7
  from twitter_openapi_python.models import (
7
8
  ApiUtilsRaw,
@@ -29,9 +30,10 @@ class UserListApiUtils:
29
30
  api: twitter.UserListApi
30
31
  flag: ParamType
31
32
 
32
- def __init__(self, api: twitter.UserListApi, flag: ParamType):
33
+ def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: ClientTransaction):
33
34
  self.api = api
34
35
  self.flag = flag
36
+ self.ct = ct
35
37
 
36
38
  def request(
37
39
  self,
@@ -40,7 +42,7 @@ class UserListApiUtils:
40
42
  key: str,
41
43
  param: ParamType,
42
44
  ) -> ResponseType:
43
- args = get_kwargs(flag=self.flag[key], additional=param)
45
+ args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
44
46
  res = apiFn(**args)
45
47
  instruction = convertFn(res.data)
46
48
  entry = instruction_to_entry(instruction)
@@ -2,6 +2,7 @@ from typing import Any, Callable, Optional, TypeVar
2
2
 
3
3
  import twitter_openapi_python_generated as twitter
4
4
  import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
5
6
 
6
7
  from twitter_openapi_python.models import TwitterApiUtilsResponse, UserApiUtilsData
7
8
  from twitter_openapi_python.utils import (
@@ -21,9 +22,10 @@ class UsersApiUtils:
21
22
  api: twitter.UsersApi
22
23
  flag: ParamType
23
24
 
24
- def __init__(self, api: twitter.UsersApi, flag: ParamType):
25
+ def __init__(self, api: twitter.UsersApi, flag: ParamType, ct: ClientTransaction):
25
26
  self.api = api
26
27
  self.flag = flag
28
+ self.ct = ct
27
29
 
28
30
  def request(
29
31
  self,
@@ -32,7 +34,7 @@ class UsersApiUtils:
32
34
  key: str,
33
35
  param: ParamType,
34
36
  ) -> ResponseType:
35
- args = get_kwargs(flag=self.flag[key], additional=param)
37
+ args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
36
38
  res = apiFn(**args)
37
39
  user_result = convertFn(res.data)
38
40
  user = user_result_converter(user_result)
@@ -5,6 +5,7 @@ from typing import Any
5
5
  import twitter_openapi_python_generated as twitter
6
6
  import twitter_openapi_python_generated.configuration as conf
7
7
  import urllib3
8
+ from x_client_transaction import ClientTransaction
8
9
 
9
10
  from twitter_openapi_python.api import (
10
11
  DefaultApiUtils,
@@ -17,6 +18,7 @@ from twitter_openapi_python.api import (
17
18
  V11GetApiUtils,
18
19
  V11PostApiUtils,
19
20
  )
21
+ from twitter_openapi_python.tid import get_tid
20
22
 
21
23
  ParamType = dict[str, Any]
22
24
 
@@ -25,40 +27,41 @@ class TwitterOpenapiPythonClient:
25
27
  api: twitter.ApiClient
26
28
  placeholder: ParamType
27
29
 
28
- def __init__(self, api: twitter.ApiClient, placeholder: ParamType):
30
+ def __init__(self, api: twitter.ApiClient, placeholder: ParamType, ct: ClientTransaction):
29
31
  self.api = api
30
32
  self.placeholder = placeholder
33
+ self.ct = ct
31
34
 
32
35
  def get_default_api(self) -> DefaultApiUtils:
33
- return DefaultApiUtils(twitter.DefaultApi(self.api), self.placeholder)
36
+ return DefaultApiUtils(twitter.DefaultApi(self.api), self.placeholder, self.ct)
34
37
 
35
38
  def get_initial_state_api(self) -> InitialStateApiUtils:
36
39
  return InitialStateApiUtils(self.api)
37
40
 
38
41
  def get_post_api(self) -> PostApiUtils:
39
- return PostApiUtils(twitter.PostApi(self.api), self.placeholder)
42
+ return PostApiUtils(twitter.PostApi(self.api), self.placeholder, self.ct)
40
43
 
41
44
  def get_tweet_api(self) -> TweetApiUtils:
42
- return TweetApiUtils(twitter.TweetApi(self.api), self.placeholder)
45
+ return TweetApiUtils(twitter.TweetApi(self.api), self.placeholder, self.ct)
43
46
 
44
47
  def get_user_api(self) -> UserApiUtils:
45
- return UserApiUtils(twitter.UserApi(self.api), self.placeholder)
48
+ return UserApiUtils(twitter.UserApi(self.api), self.placeholder, self.ct)
46
49
 
47
50
  def get_users_api(self) -> UsersApiUtils:
48
- return UsersApiUtils(twitter.UsersApi(self.api), self.placeholder)
51
+ return UsersApiUtils(twitter.UsersApi(self.api), self.placeholder, self.ct)
49
52
 
50
53
  def get_user_list_api(self) -> UserListApiUtils:
51
- return UserListApiUtils(twitter.UserListApi(self.api), self.placeholder)
54
+ return UserListApiUtils(twitter.UserListApi(self.api), self.placeholder, self.ct)
52
55
 
53
56
  def get_v11_get_api(self) -> V11GetApiUtils:
54
- return V11GetApiUtils(twitter.V11GetApi(self.api), self.placeholder)
57
+ return V11GetApiUtils(twitter.V11GetApi(self.api), self.placeholder, self.ct)
55
58
 
56
59
  def get_v11_post_api(self) -> V11PostApiUtils:
57
- return V11PostApiUtils(twitter.V11PostApi(self.api), self.placeholder)
60
+ return V11PostApiUtils(twitter.V11PostApi(self.api), self.placeholder, self.ct)
58
61
 
59
62
 
60
63
  class TwitterOpenapiPython:
61
- hash: str = "227f4e3716dbb034500945c378bd7874b611f8f5"
64
+ hash: str = "54acb4a0cef6aea969d3a1c75d37d58d80b0e5c0"
62
65
  placeholder_url = "https://raw.githubusercontent.com/fa0311/twitter-openapi/{hash}/src/config/placeholder.json"
63
66
  header = "https://raw.githubusercontent.com/fa0311/latest-user-agent/refs/heads/main/header.json"
64
67
  access_token: str = (
@@ -123,7 +126,8 @@ class TwitterOpenapiPython:
123
126
  ) -> TwitterOpenapiPythonClient:
124
127
  http = urllib3.PoolManager()
125
128
  flag = http.request("GET", self.placeholder_url.format(hash=self.hash))
126
- return TwitterOpenapiPythonClient(api, json.loads(flag.data))
129
+ ct = get_tid()
130
+ return TwitterOpenapiPythonClient(api, json.loads(flag.data), ct)
127
131
 
128
132
  def get_client_from_cookies(
129
133
  self,
@@ -0,0 +1,17 @@
1
+ import bs4
2
+ import requests
3
+ from x_client_transaction import ClientTransaction
4
+ from x_client_transaction.utils import generate_headers, get_ondemand_file_url, handle_x_migration
5
+
6
+
7
+ def get_tid():
8
+ session = requests.Session()
9
+ session.headers = generate_headers() # type: ignore
10
+ home_page_response = handle_x_migration(session=session)
11
+ home_page = session.get(url="https://x.com")
12
+ home_page_response = bs4.BeautifulSoup(home_page.content, "html.parser")
13
+ ondemand_file_url = get_ondemand_file_url(response=home_page_response)
14
+ ondemand_file = session.get(url=ondemand_file_url) # type: ignore
15
+ ondemand_file_response = bs4.BeautifulSoup(ondemand_file.content, "html.parser")
16
+ ct = ClientTransaction(home_page_response=home_page_response, ondemand_file_response=ondemand_file_response)
17
+ return ct
@@ -3,6 +3,7 @@ from typing import Any, Dict, List, Mapping, Optional, TypeGuard, TypeVar
3
3
 
4
4
  import twitter_openapi_python_generated as twitter
5
5
  import twitter_openapi_python_generated.models as models
6
+ from x_client_transaction import ClientTransaction
6
7
 
7
8
  from twitter_openapi_python.models import (
8
9
  ApiUtilsHeader,
@@ -36,7 +37,7 @@ def non_nullable_list(x: List[Optional[T]]) -> List[T]:
36
37
  return list(filter(filter_fn, x))
37
38
 
38
39
 
39
- def get_kwargs(flag: ParamType, additional: ParamType) -> ParamType:
40
+ def get_kwargs(flag: ParamType, additional: ParamType, ct: ClientTransaction) -> ParamType:
40
41
  assert flag is not None
41
42
  kwargs = {"path_query_id": flag["queryId"]}
42
43
  if flag.get("variables") is not None:
@@ -45,9 +46,16 @@ def get_kwargs(flag: ParamType, additional: ParamType) -> ParamType:
45
46
  kwargs["features"] = json.dumps(flag["features"])
46
47
  if flag.get("fieldToggles") is not None:
47
48
  kwargs["field_toggles"] = json.dumps(flag["fieldToggles"])
49
+ if flag.get("@path") is not None:
50
+ kwargs["_headers"] = get_headers(flag, ct)
48
51
  return kwargs
49
52
 
50
53
 
54
+ def get_headers(flag: ParamType, ct: ClientTransaction) -> Dict[str, str]:
55
+ tid = ct.generate_transaction_id(flag["@method"], flag["@path"])
56
+ return {"x-client-transaction-id": tid}
57
+
58
+
51
59
  def get_legacy_kwargs(flag: ParamType, additional: ParamType) -> ParamType:
52
60
  assert flag is not None
53
61
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: twitter-openapi-python
3
- Version: 0.0.35
3
+ Version: 0.0.37
4
4
  Summary: Twitter OpenAPI
5
5
  Home-page: https://github.com/fa0311/twitter_openapi_python
6
6
  Author: fa0311
@@ -6,6 +6,7 @@ setup.py
6
6
  twitter_openapi_python/__init__.py
7
7
  twitter_openapi_python/client.py
8
8
  twitter_openapi_python/py.typed
9
+ twitter_openapi_python/tid.py
9
10
  twitter_openapi_python.egg-info/PKG-INFO
10
11
  twitter_openapi_python.egg-info/SOURCES.txt
11
12
  twitter_openapi_python.egg-info/dependency_links.txt
@@ -0,0 +1,3 @@
1
+ twitter_openapi_python_generated==0.0.33
2
+ pydantic>=2.6
3
+ urllib3<3.0.0,>=2.1.0
@@ -1,3 +0,0 @@
1
- twitter_openapi_python_generated==0.0.31
2
- pydantic>=2.6
3
- urllib3<3.0.0,>=2.1.0