twitter-openapi-python 0.0.22__py3-none-any.whl → 0.0.23__py3-none-any.whl

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.
@@ -24,7 +24,8 @@ class InitialStateApiUtils:
24
24
  }
25
25
 
26
26
  def request(self, url: str) -> HTTPResponse:
27
- return self.api.rest_client.get_request(
27
+ return self.api.rest_client.request(
28
+ "GET",
28
29
  url=url,
29
30
  headers=self.header,
30
31
  )
@@ -4,7 +4,7 @@ import twitter_openapi_python_generated as twitter
4
4
  import twitter_openapi_python_generated.models as models
5
5
 
6
6
  from twitter_openapi_python.models import TwitterApiUtilsResponse
7
- from twitter_openapi_python.utils import build_response, check_error
7
+ from twitter_openapi_python.utils import build_response, check_error, non_nullable
8
8
 
9
9
  T = TypeVar("T")
10
10
  ResponseType = TwitterApiUtilsResponse[T]
@@ -32,11 +32,15 @@ class PostApiUtils:
32
32
  tweet_text: str,
33
33
  media_ids: Optional[list[str]] = None,
34
34
  ) -> ResponseType[models.CreateTweetResponse]:
35
- variables = twitter.PostCreateTweetRequestVariables.from_dict(
36
- self.flag["CreateTweet"]["variables"]
35
+ variables = non_nullable(
36
+ twitter.PostCreateTweetRequestVariables.from_dict(
37
+ self.flag["CreateTweet"]["variables"]
38
+ )
37
39
  )
38
- features = twitter.PostCreateTweetRequestFeatures.from_dict(
39
- self.flag["CreateTweet"]["features"]
40
+ features = non_nullable(
41
+ twitter.PostCreateTweetRequestFeatures.from_dict(
42
+ self.flag["CreateTweet"]["features"]
43
+ )
40
44
  )
41
45
  variables.tweet_text = tweet_text
42
46
  variables.media.media_entities = [
@@ -62,8 +66,10 @@ class PostApiUtils:
62
66
  self,
63
67
  tweet_id: str,
64
68
  ) -> ResponseType[models.DeleteTweetResponse]:
65
- variables = twitter.PostCreateRetweetRequestVariables.from_dict(
66
- self.flag["DeleteTweet"]["variables"]
69
+ variables = non_nullable(
70
+ twitter.PostCreateRetweetRequestVariables.from_dict(
71
+ self.flag["DeleteTweet"]["variables"]
72
+ )
67
73
  )
68
74
  variables.tweet_id = tweet_id
69
75
 
@@ -81,8 +87,10 @@ class PostApiUtils:
81
87
  self,
82
88
  tweet_id: str,
83
89
  ) -> ResponseType[models.CreateRetweetResponse]:
84
- variables = twitter.PostCreateRetweetRequestVariables.from_dict(
85
- self.flag["CreateRetweet"]["variables"]
90
+ variables = non_nullable(
91
+ twitter.PostCreateRetweetRequestVariables.from_dict(
92
+ self.flag["CreateRetweet"]["variables"]
93
+ )
86
94
  )
87
95
  variables.tweet_id = tweet_id
88
96
 
@@ -100,8 +108,10 @@ class PostApiUtils:
100
108
  self,
101
109
  source_tweet_id: str,
102
110
  ) -> ResponseType[models.DeleteRetweetResponse]:
103
- variables = twitter.PostDeleteRetweetRequestVariables.from_dict(
104
- self.flag["DeleteRetweet"]["variables"]
111
+ variables = non_nullable(
112
+ twitter.PostDeleteRetweetRequestVariables.from_dict(
113
+ self.flag["DeleteRetweet"]["variables"]
114
+ )
105
115
  )
106
116
  variables.source_tweet_id = source_tweet_id
107
117
 
@@ -120,8 +130,10 @@ class PostApiUtils:
120
130
  self,
121
131
  tweet_id: str,
122
132
  ) -> ResponseType[models.FavoriteTweetResponseData]:
123
- variables = twitter.PostCreateRetweetRequestVariables.from_dict(
124
- self.flag["FavoriteTweet"]["variables"]
133
+ variables = non_nullable(
134
+ twitter.PostCreateBookmarkRequestVariables.from_dict(
135
+ self.flag["FavoriteTweet"]["variables"]
136
+ )
125
137
  )
126
138
  variables.tweet_id = tweet_id
127
139
 
@@ -139,8 +151,10 @@ class PostApiUtils:
139
151
  self,
140
152
  tweet_id: str,
141
153
  ) -> ResponseType[models.UnfavoriteTweetResponseData]:
142
- variables = twitter.PostCreateRetweetRequestVariables.from_dict(
143
- self.flag["UnfavoriteTweet"]["variables"]
154
+ variables = non_nullable(
155
+ twitter.PostCreateRetweetRequestVariables.from_dict(
156
+ self.flag["UnfavoriteTweet"]["variables"]
157
+ )
144
158
  )
145
159
  variables.tweet_id = tweet_id
146
160
 
@@ -17,6 +17,7 @@ from twitter_openapi_python.utils import (
17
17
  instruction_to_entry,
18
18
  tweet_entries_converter,
19
19
  )
20
+ from twitter_openapi_python.utils.api import non_nullable
20
21
 
21
22
  T = TypeVar("T")
22
23
  ResponseType = TwitterApiUtilsResponse[TimelineApiUtilsResponse[TweetApiUtilsData]]
@@ -199,7 +200,9 @@ class TweetApiUtils:
199
200
 
200
201
  response = self.request(
201
202
  apiFn=self.api.get_user_tweets_with_http_info,
202
- convertFn=lambda e: e.data.user.result.timeline_v2.timeline.instructions,
203
+ convertFn=lambda e: non_nullable(
204
+ e.data.user.result.timeline_v2.timeline
205
+ ).instructions,
203
206
  type=models.UserTweetsResponse,
204
207
  key="UserTweets",
205
208
  param=param,
@@ -223,7 +226,9 @@ class TweetApiUtils:
223
226
 
224
227
  response = self.request(
225
228
  apiFn=self.api.get_user_tweets_and_replies_with_http_info,
226
- convertFn=lambda e: e.data.user.result.timeline_v2.timeline.instructions,
229
+ convertFn=lambda e: non_nullable(
230
+ e.data.user.result.timeline_v2.timeline
231
+ ).instructions,
227
232
  type=models.UserTweetsResponse,
228
233
  key="UserTweetsAndReplies",
229
234
  param=param,
@@ -247,7 +252,9 @@ class TweetApiUtils:
247
252
 
248
253
  response = self.request(
249
254
  apiFn=self.api.get_user_media_with_http_info,
250
- convertFn=lambda e: e.data.user.result.timeline_v2.timeline.instructions,
255
+ convertFn=lambda e: non_nullable(
256
+ e.data.user.result.timeline_v2.timeline
257
+ ).instructions,
251
258
  type=models.UserTweetsResponse,
252
259
  key="UserMedia",
253
260
  param=param,
@@ -271,7 +278,9 @@ class TweetApiUtils:
271
278
 
272
279
  response = self.request(
273
280
  apiFn=self.api.get_likes_with_http_info,
274
- convertFn=lambda e: e.data.user.result.timeline_v2.timeline.instructions,
281
+ convertFn=lambda e: non_nullable(
282
+ e.data.user.result.timeline_v2.timeline
283
+ ).instructions,
275
284
  type=models.UserTweetsResponse,
276
285
  key="Likes",
277
286
  param=param,
@@ -15,6 +15,7 @@ from twitter_openapi_python.utils import (
15
15
  entries_cursor,
16
16
  get_kwargs,
17
17
  instruction_to_entry,
18
+ non_nullable,
18
19
  user_entries_converter,
19
20
  user_result_converter,
20
21
  )
@@ -144,7 +145,9 @@ class UserListApiUtils:
144
145
  param.update(extra_param)
145
146
  return self.request(
146
147
  apiFn=self.api.get_favoriters_with_http_info,
147
- convertFn=lambda e: e.data.favoriters_timeline.timeline.instructions,
148
+ convertFn=lambda e: non_nullable(
149
+ e.data.favoriters_timeline.timeline
150
+ ).instructions,
148
151
  type=models.TweetFavoritersResponse,
149
152
  key="Favoriters",
150
153
  param=param,
@@ -166,7 +169,9 @@ class UserListApiUtils:
166
169
  param.update(extra_param)
167
170
  return self.request(
168
171
  apiFn=self.api.get_retweeters_with_http_info,
169
- convertFn=lambda e: e.data.retweeters_timeline.timeline.instructions,
172
+ convertFn=lambda e: non_nullable(
173
+ e.data.retweeters_timeline.timeline
174
+ ).instructions,
170
175
  type=models.TweetRetweetersResponse,
171
176
  key="Retweeters",
172
177
  param=param,
@@ -58,10 +58,10 @@ class TwitterOpenapiPythonClient:
58
58
 
59
59
 
60
60
  class TwitterOpenapiPython:
61
- hash: str = "4f39fa1a95e3b03fcc64ae4c54c3d4389582fd39"
61
+ hash: str = "a18a24e4fd96967314c452a6ec2fe6e54f112351"
62
62
  placeholder_url = "https://raw.githubusercontent.com/fa0311/twitter-openapi/{hash}/src/config/placeholder.json"
63
63
  placeholder: ParamType
64
- user_agent: str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
64
+ user_agent: str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
65
65
  access_token: str = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
66
66
 
67
67
  api_key = {
@@ -141,7 +141,7 @@ class TwitterOpenapiPython:
141
141
 
142
142
  res_1 = http.request(
143
143
  "GET",
144
- "https://twitter.com",
144
+ "https://x.com",
145
145
  redirect=False,
146
146
  headers=self.browser_headers.copy(),
147
147
  )
@@ -149,7 +149,7 @@ class TwitterOpenapiPython:
149
149
  session.update(self.cookie_normalize(cookie))
150
150
  res_2 = http.request(
151
151
  "GET",
152
- "https://twitter.com",
152
+ "https://x.com",
153
153
  redirect=False,
154
154
  headers=self.browser_headers.copy()
155
155
  | {"Cookie": self.cookie_to_str(session)},
@@ -168,7 +168,7 @@ class TwitterOpenapiPython:
168
168
  }
169
169
  res_3 = http.request(
170
170
  "POST",
171
- "https://api.twitter.com/1.1/guest/activate.json",
171
+ "https://api.x.com/1.1/guest/activate.json",
172
172
  headers=activate_header | {"Cookie": self.cookie_to_str(session)},
173
173
  )
174
174
  gt = json.loads(res_3.data.decode())["guest_token"]
@@ -18,4 +18,5 @@ from twitter_openapi_python.utils.api import (
18
18
  user_entries_converter,
19
19
  user_or_null_converter,
20
20
  user_result_converter,
21
+ non_nullable,
21
22
  )
@@ -23,6 +23,11 @@ def flat(matrix: List[List[T]]) -> List[T]:
23
23
  return [x for row in matrix for x in row]
24
24
 
25
25
 
26
+ def non_nullable(x: Optional[T]) -> T:
27
+ if x is None:
28
+ raise Exception("No data")
29
+ return x
30
+
26
31
  def non_nullable_list(x: List[Optional[T]]) -> List[T]:
27
32
  def filter_fn(x: Optional[T]) -> TypeGuard[T]:
28
33
  return x is not None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: twitter-openapi-python
3
- Version: 0.0.22
3
+ Version: 0.0.23
4
4
  Summary: Twitter OpenAPI
5
5
  Home-page: https://github.com/fa0311/twitter_openapi_python
6
6
  Author: fa0311
@@ -10,7 +10,7 @@ Keywords: OpenAPI,OpenAPI-Generator,Twitter OpenAPI
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
12
  License-File: LICENSE.AGPL
13
- Requires-Dist: twitter-openapi-python-generated ==0.0.16
13
+ Requires-Dist: twitter-openapi-python-generated ==0.0.20
14
14
  Requires-Dist: pydantic >=2.6
15
15
 
16
16
  Twitter scraping with data validation by pydantic.
@@ -1,13 +1,13 @@
1
1
  twitter_openapi_python/__init__.py,sha256=stqYIfWDqM0yC93SQNp4-b2hSz-ONWR3QxOG5g2oREg,339
2
- twitter_openapi_python/client.py,sha256=HzxtpWo-yNzIlfPIZKbAxM8QidAw2E83bwLUd7lfcQE,6500
2
+ twitter_openapi_python/client.py,sha256=vLJsD49AzN4nvrLlNmRQgdN4Fn8VBoT9eyq-vOwZzwU,6482
3
3
  twitter_openapi_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  twitter_openapi_python/api/__init__.py,sha256=-2hoS75Fp0KvCIWKYQFpvAl0pcbFyt7Be3ood08P7n8,643
5
5
  twitter_openapi_python/api/default_api.py,sha256=PeHYaAw6xaUB9ZE3An5SKcEvW71JLTFSgyte80BBvX4,2751
6
- twitter_openapi_python/api/initial_state_api.py,sha256=b_ehegseXC3dtGEQ99QEg5g7-KGuZWM3VT4iWkkK3W8,2339
7
- twitter_openapi_python/api/post_api.py,sha256=q9v-AUZXOmrZ28seD81hOO8bIXbqB5S0vN-QkJlmuIc,5607
8
- twitter_openapi_python/api/tweet_api.py,sha256=eP1pbtCB2dV9rbI3M5R9ta_CyViBngnSLWZztMfEycU,9941
6
+ twitter_openapi_python/api/initial_state_api.py,sha256=N4yA3oXDbke7bH-XOuKQ4WVUm5sKbC2C3Dd3AvFINLY,2355
7
+ twitter_openapi_python/api/post_api.py,sha256=W85UFViBoElS8T2-E9teRcC-9ngcSapoymZWoIb3qno,5944
8
+ twitter_openapi_python/api/tweet_api.py,sha256=iZC3PlFS9SD3olb4BRrMYfyoCUf1UuD2XToXd33S-UM,10184
9
9
  twitter_openapi_python/api/user_api.py,sha256=oH5JBNemBSCyUFAbDSDbjRUOZN3bZMa_tI8PQ4C1wYk,2619
10
- twitter_openapi_python/api/user_list_api.py,sha256=nhLbqXF4nnM9ONTGa-Szh5booZk5LeEfOfR7lEYyT1M,5637
10
+ twitter_openapi_python/api/user_list_api.py,sha256=7o1dqRrXzk0F6ywQ-dhyMR0eCzsGJ6HeUHYswPDx3hI,5748
11
11
  twitter_openapi_python/api/users_api.py,sha256=82CM20-dp7JfpTRqSIzU5Lbm4xoB32Cq18ECRfVMt_I,1789
12
12
  twitter_openapi_python/api/v11_get_api.py,sha256=OimuRRA4oG2z6IGhJuzgo2CvJqpoD4-CDNZrwZRg6GQ,2254
13
13
  twitter_openapi_python/api/v11_post_api.py,sha256=d7H-ewGhLql-lQagkGLdOm9FybtjN05lCoGatDMh9rc,2051
@@ -17,11 +17,11 @@ twitter_openapi_python/models/header.py,sha256=hP0fjrm-3Mogt9IkAucQnmDletRuzMmCf
17
17
  twitter_openapi_python/models/initial_state.py,sha256=h8P3hC_tLVSmDuYxB03fuSviz22cpp-4RfSR2npP_Yo,530
18
18
  twitter_openapi_python/models/response.py,sha256=ZuaX36mKRsVx5aiJhNw3CjrvVGVaGjMCGdXy28PMFy8,480
19
19
  twitter_openapi_python/models/timeline.py,sha256=AoWfrJsonYImlweciaUSjFzmeciaX0zshi7d-FkT4LM,1392
20
- twitter_openapi_python/utils/__init__.py,sha256=U31tIEyCWa4RRnYvMXqcdtHTpbEUftNey68XmAP0lnk,430
21
- twitter_openapi_python/utils/api.py,sha256=G7h83x_BcXP9ou_XlYEFd4M4yElG7Ck-U8W8dvWkFaI,9915
22
- twitter_openapi_python-0.0.22.dist-info/LICENSE,sha256=xthyYzrtSmRlBu2gnfuIxzsZeHrqtIZgZPL9UPrYiQU,1524
23
- twitter_openapi_python-0.0.22.dist-info/LICENSE.AGPL,sha256=Nv6u1ubULm-E2y6q2-pQPK8s2BzkOltLaVlPKQ3tkcs,35182
24
- twitter_openapi_python-0.0.22.dist-info/METADATA,sha256=xZForYf3jllPiDsMYdI9hFfaiXeMgYy8Dkrgqj7qDas,551
25
- twitter_openapi_python-0.0.22.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
26
- twitter_openapi_python-0.0.22.dist-info/top_level.txt,sha256=wKFCnW_S6aWD3nFPmd65SxZIviiqQ30LqHOLLpcnTdE,23
27
- twitter_openapi_python-0.0.22.dist-info/RECORD,,
20
+ twitter_openapi_python/utils/__init__.py,sha256=QVT1eCClP9EVfcZ4QU96TVegfAUDEtJ-PVp3zv6qy6w,449
21
+ twitter_openapi_python/utils/api.py,sha256=JTSXE1Wh3AiuOb_APTDTQMrR4HTkI9AihzrXkJGV2d8,10026
22
+ twitter_openapi_python-0.0.23.dist-info/LICENSE,sha256=xthyYzrtSmRlBu2gnfuIxzsZeHrqtIZgZPL9UPrYiQU,1524
23
+ twitter_openapi_python-0.0.23.dist-info/LICENSE.AGPL,sha256=Nv6u1ubULm-E2y6q2-pQPK8s2BzkOltLaVlPKQ3tkcs,35182
24
+ twitter_openapi_python-0.0.23.dist-info/METADATA,sha256=NqIdS2rue_6LZmO73CSxjpeNebHwrIdQkXrQOixJOio,551
25
+ twitter_openapi_python-0.0.23.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
26
+ twitter_openapi_python-0.0.23.dist-info/top_level.txt,sha256=wKFCnW_S6aWD3nFPmd65SxZIviiqQ30LqHOLLpcnTdE,23
27
+ twitter_openapi_python-0.0.23.dist-info/RECORD,,