twitter-openapi-python 0.0.12__py3-none-any.whl → 0.0.15__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.
@@ -66,7 +66,8 @@ class TwitterOpenapiPython:
66
66
 
67
67
  api_key = {
68
68
  "Accept": "*/*",
69
- "AcceptEncoding": "gzip, deflate, br",
69
+ # "AcceptEncoding": "gzip, deflate, br",
70
+ # "AcceptEncoding": "deflate, br",
70
71
  "AcceptLanguage": "en-US,en;q=0.9",
71
72
  "CacheControl": "no-cache",
72
73
  "Pragma": "no-cache",
@@ -109,14 +110,14 @@ class TwitterOpenapiPython:
109
110
  api: twitter.ApiClient,
110
111
  ) -> TwitterOpenapiPythonClient:
111
112
  http = urllib3.PoolManager()
112
- flag = http.request("GET", self.placeholder_url.format(hash=self.hash)).json()
113
- return TwitterOpenapiPythonClient(api, flag)
113
+ flag = http.request("GET", self.placeholder_url.format(hash=self.hash))
114
+ return TwitterOpenapiPythonClient(api, json.loads(flag.data))
114
115
 
115
116
  def get_client_from_cookies(
116
117
  self,
117
118
  cookies: dict[str, str],
118
119
  ) -> TwitterOpenapiPythonClient:
119
- api_key = self.api_key
120
+ api_key = self.api_key.copy()
120
121
 
121
122
  if cookies.get("ct0"):
122
123
  api_key.update({"AuthType": "OAuth2Session"})
@@ -142,7 +143,7 @@ class TwitterOpenapiPython:
142
143
  "GET",
143
144
  "https://twitter.com",
144
145
  redirect=False,
145
- headers=self.browser_headers,
146
+ headers=self.browser_headers.copy(),
146
147
  )
147
148
  cookie = res_1.headers._container["set-cookie"][1:]
148
149
  session.update(self.cookie_normalize(cookie))
@@ -150,7 +151,8 @@ class TwitterOpenapiPython:
150
151
  "GET",
151
152
  "https://twitter.com",
152
153
  redirect=False,
153
- headers=self.browser_headers | {"Cookie": self.cookie_to_str(session)},
154
+ headers=self.browser_headers.copy()
155
+ | {"Cookie": self.cookie_to_str(session)},
154
156
  )
155
157
 
156
158
  find = re.findall(r'document.cookie="(.*?)";', res_2.data.decode())
@@ -159,7 +161,7 @@ class TwitterOpenapiPython:
159
161
  session.pop("ct0")
160
162
 
161
163
  if not session.get("gt"):
162
- activate_header = self.browser_headers | {
164
+ activate_header = self.browser_headers.copy() | {
163
165
  "authorization": "Bearer {}".format(self.access_token),
164
166
  "x-twitter-active-user": "yes",
165
167
  "x-twitter-client-language": "en",
@@ -3,7 +3,7 @@
3
3
  # flake8: noqa
4
4
 
5
5
 
6
- from twitter_openapi_python.models.base import BaseModel, GenericModel
6
+ from twitter_openapi_python.models.base import BaseModel
7
7
  from twitter_openapi_python.models.header import ApiUtilsHeader
8
8
  from twitter_openapi_python.models.initial_state import (
9
9
  InitialStateApiUtilsRaw,
@@ -1,12 +1,9 @@
1
- from pydantic import BaseModel as PydanticBaseModel
2
- from pydantic.generics import GenericModel as PydanticGenericModel
1
+ from typing import TypeVar
3
2
 
3
+ from pydantic import BaseModel as PydanticBaseModel
4
4
 
5
- class BaseModel(PydanticBaseModel):
6
- class Config:
7
- arbitrary_types_allowed = True
5
+ T = TypeVar("T")
8
6
 
9
7
 
10
- class GenericModel(PydanticGenericModel):
11
- class Config:
12
- arbitrary_types_allowed = True
8
+ class BaseModel(PydanticBaseModel):
9
+ model_config = {"arbitrary_types_allowed": True}
@@ -3,7 +3,7 @@ from typing import Generic, TypeVar
3
3
  import twitter_openapi_python_generated as twitter
4
4
  from pydantic import Field
5
5
 
6
- from twitter_openapi_python.models import ApiUtilsHeader, BaseModel, GenericModel
6
+ from twitter_openapi_python.models import ApiUtilsHeader, BaseModel
7
7
 
8
8
  T1 = TypeVar("T1")
9
9
  T2 = TypeVar("T2")
@@ -13,7 +13,7 @@ class TwitterApiUtilsRaw(BaseModel):
13
13
  response: twitter.ApiResponse = Field()
14
14
 
15
15
 
16
- class TwitterApiUtilsResponse(GenericModel, Generic[T1]):
16
+ class TwitterApiUtilsResponse(BaseModel, Generic[T1]):
17
17
  raw: TwitterApiUtilsRaw = Field()
18
18
  data: T1 = Field()
19
19
  header: ApiUtilsHeader = Field()
@@ -4,7 +4,7 @@ from typing import Any, Generic, List, Optional, TypeVar
4
4
  import twitter_openapi_python_generated.models as models
5
5
  from pydantic import Field
6
6
 
7
- from twitter_openapi_python.models import BaseModel, GenericModel
7
+ from twitter_openapi_python.models import BaseModel
8
8
 
9
9
  T = TypeVar("T")
10
10
 
@@ -34,7 +34,7 @@ class UserApiUtilsData(BaseModel):
34
34
  user: models.User = Field()
35
35
 
36
36
 
37
- class TimelineApiUtilsResponse(GenericModel, Generic[T]):
37
+ class TimelineApiUtilsResponse(BaseModel, Generic[T]):
38
38
  raw: ApiUtilsRaw = Field()
39
39
  cursor: CursorApiUtilsResponse = Field()
40
40
  data: List[T] = Field(default_factory=list)
@@ -1,5 +1,5 @@
1
1
  import json
2
- from typing import Any, Dict, List, Optional, TypeGuard, TypeVar
2
+ 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
@@ -83,35 +83,55 @@ def instruction_to_entry(
83
83
  def tweet_entries_converter(
84
84
  input: List[models.TimelineAddEntry],
85
85
  ) -> List[TweetApiUtilsData]:
86
- def map_fn(x: models.TimelineAddEntry) -> Optional[TweetApiUtilsData]:
86
+ def map_fn(x: models.TimelineAddEntry) -> Optional[List[TweetApiUtilsData]]:
87
87
  one_of = x.content.actual_instance
88
88
 
89
89
  if isinstance(one_of, models.TimelineTimelineItem):
90
90
  item = one_of.item_content.actual_instance
91
91
  if isinstance(item, models.TimelineTweet):
92
- return build_tweet_api_utils(
93
- result=item.tweet_results,
94
- promoted_metadata=item.promoted_metadata,
95
- reply=[],
92
+ return non_nullable_list(
93
+ [
94
+ build_tweet_api_utils(
95
+ result=item.tweet_results,
96
+ promoted_metadata=item.promoted_metadata,
97
+ reply=[],
98
+ )
99
+ ]
96
100
  )
97
101
  elif isinstance(one_of, models.TimelineTimelineModule):
98
102
  module = one_of.items or []
99
103
  timelineList = non_nullable_list(list(map(map_fn_2, module)))
100
104
  if len(timelineList) == 0:
101
105
  return None
102
- timeline = timelineList[0]
103
- return build_tweet_api_utils(
104
- result=timeline.tweet_results,
105
- promoted_metadata=timeline.promoted_metadata,
106
- reply=timelineList[1:],
107
- )
106
+ if one_of.display_type == models.DisplayType.VERTICALGRID:
107
+ return non_nullable_list(
108
+ [
109
+ build_tweet_api_utils(
110
+ result=x.tweet_results,
111
+ promoted_metadata=x.promoted_metadata,
112
+ reply=[],
113
+ )
114
+ for x in timelineList
115
+ ]
116
+ )
117
+ else:
118
+ timeline = timelineList[0]
119
+ return non_nullable_list(
120
+ [
121
+ build_tweet_api_utils(
122
+ result=timeline.tweet_results,
123
+ promoted_metadata=timeline.promoted_metadata,
124
+ reply=timelineList[1:],
125
+ )
126
+ ]
127
+ )
108
128
 
109
129
  def map_fn_2(x: models.ModuleItem) -> Optional[models.TimelineTweet]:
110
130
  item = x.item.item_content.actual_instance
111
131
  if isinstance(item, models.TimelineTweet):
112
132
  return item
113
133
 
114
- return non_nullable_list(list(map(map_fn, input)))
134
+ return flat(non_nullable_list(list(map(map_fn, input))))
115
135
 
116
136
 
117
137
  def user_or_null_converter(user: models.UserUnion) -> Optional[models.User]:
@@ -245,7 +265,12 @@ def build_response(
245
265
  if response.headers is None:
246
266
  raise Exception("headers is None")
247
267
 
248
- header = build_header(response.headers)
268
+ if isinstance(response.headers, Dict):
269
+ header = build_header(response.headers)
270
+ elif isinstance(response.headers, Mapping):
271
+ header = build_header(dict(response.headers))
272
+ else:
273
+ raise Exception("headers is not a dict")
249
274
 
250
275
  return TwitterApiUtilsResponse(
251
276
  raw=TwitterApiUtilsRaw(response=response),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: twitter-openapi-python
3
- Version: 0.0.12
3
+ Version: 0.0.15
4
4
  Summary: Twitter OpenAPI
5
5
  Home-page: https://github.com/fa0311/twitter_openapi_python
6
6
  Author: fa0311
@@ -10,8 +10,8 @@ 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.6
14
- Requires-Dist: pydantic <2,>=1.10.5
13
+ Requires-Dist: twitter-openapi-python-generated ==0.0.9
14
+ Requires-Dist: pydantic >=2.6
15
15
 
16
16
  Twitter scraping with data validation by pydantic.
17
17
 
@@ -1,5 +1,5 @@
1
1
  twitter_openapi_python/__init__.py,sha256=stqYIfWDqM0yC93SQNp4-b2hSz-ONWR3QxOG5g2oREg,339
2
- twitter_openapi_python/client.py,sha256=ulxrA7II5Efw8u7rRp600VoCjDZe2wSPPGsVGLkk0QI,6403
2
+ twitter_openapi_python/client.py,sha256=eFfafgpGhD-x3qHawQAf2XjD0x4zcqUwwF-FRVp9LqE,6500
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
@@ -11,17 +11,17 @@ twitter_openapi_python/api/user_list_api.py,sha256=nhLbqXF4nnM9ONTGa-Szh5booZk5L
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
14
- twitter_openapi_python/models/__init__.py,sha256=hZZYM0Ly9jzADqwVKHyniTbktFdoLmJDo33fkivj1F8,597
15
- twitter_openapi_python/models/base.py,sha256=cHBRhpFJQN6NIqvWdOv1NQygAwURv1yEfw4msBrDKqY,327
14
+ twitter_openapi_python/models/__init__.py,sha256=uKZYFWWoXinGRjMU7ErbunUhfsThEuZf8aGFBd7lus0,583
15
+ twitter_openapi_python/models/base.py,sha256=3C1SKqgEZhf3QQIHPNob5vasEV7FE8KxP9rNwWYmHG0,198
16
16
  twitter_openapi_python/models/header.py,sha256=hP0fjrm-3Mogt9IkAucQnmDletRuzMmCfoEBaAtoyJ0,594
17
17
  twitter_openapi_python/models/initial_state.py,sha256=h8P3hC_tLVSmDuYxB03fuSviz22cpp-4RfSR2npP_Yo,530
18
- twitter_openapi_python/models/response.py,sha256=PW-TBYa2mG9ypSIg_hrOlJK_-8n4DoGQOut5HNGn3kM,497
19
- twitter_openapi_python/models/timeline.py,sha256=XuvcIALfEyB_4Mk8yB6bS9y0KNzda02nWjebqZLui80,1409
18
+ twitter_openapi_python/models/response.py,sha256=ZuaX36mKRsVx5aiJhNw3CjrvVGVaGjMCGdXy28PMFy8,480
19
+ twitter_openapi_python/models/timeline.py,sha256=AoWfrJsonYImlweciaUSjFzmeciaX0zshi7d-FkT4LM,1392
20
20
  twitter_openapi_python/utils/__init__.py,sha256=U31tIEyCWa4RRnYvMXqcdtHTpbEUftNey68XmAP0lnk,430
21
- twitter_openapi_python/utils/api.py,sha256=UCAPQaNNCKelZvCtL9jffGk_GHPpqCgS8B90t4SUU9Q,8894
22
- twitter_openapi_python-0.0.12.dist-info/LICENSE,sha256=xthyYzrtSmRlBu2gnfuIxzsZeHrqtIZgZPL9UPrYiQU,1524
23
- twitter_openapi_python-0.0.12.dist-info/LICENSE.AGPL,sha256=Nv6u1ubULm-E2y6q2-pQPK8s2BzkOltLaVlPKQ3tkcs,35182
24
- twitter_openapi_python-0.0.12.dist-info/METADATA,sha256=LHymmk7edX7lqDRUGxJ2aun2aby9I7LU86ZdJr_DTl0,556
25
- twitter_openapi_python-0.0.12.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
26
- twitter_openapi_python-0.0.12.dist-info/top_level.txt,sha256=wKFCnW_S6aWD3nFPmd65SxZIviiqQ30LqHOLLpcnTdE,23
27
- twitter_openapi_python-0.0.12.dist-info/RECORD,,
21
+ twitter_openapi_python/utils/api.py,sha256=G7h83x_BcXP9ou_XlYEFd4M4yElG7Ck-U8W8dvWkFaI,9915
22
+ twitter_openapi_python-0.0.15.dist-info/LICENSE,sha256=xthyYzrtSmRlBu2gnfuIxzsZeHrqtIZgZPL9UPrYiQU,1524
23
+ twitter_openapi_python-0.0.15.dist-info/LICENSE.AGPL,sha256=Nv6u1ubULm-E2y6q2-pQPK8s2BzkOltLaVlPKQ3tkcs,35182
24
+ twitter_openapi_python-0.0.15.dist-info/METADATA,sha256=VzI-OeJMiNX7rc4YOEkpC9nX1p6HxWX5cbCvoY953DY,550
25
+ twitter_openapi_python-0.0.15.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
26
+ twitter_openapi_python-0.0.15.dist-info/top_level.txt,sha256=wKFCnW_S6aWD3nFPmd65SxZIviiqQ30LqHOLLpcnTdE,23
27
+ twitter_openapi_python-0.0.15.dist-info/RECORD,,