twitter-openapi-python 0.0.12__tar.gz → 0.0.15__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.12 → twitter_openapi_python-0.0.15}/PKG-INFO +1 -1
  2. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/pyproject.toml +3 -3
  3. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/setup.py +3 -3
  4. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/client.py +9 -7
  5. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/models/__init__.py +1 -1
  6. twitter_openapi_python-0.0.15/twitter_openapi_python/models/base.py +9 -0
  7. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/models/response.py +2 -2
  8. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/models/timeline.py +2 -2
  9. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/utils/api.py +39 -14
  10. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python.egg-info/PKG-INFO +1 -1
  11. twitter_openapi_python-0.0.15/twitter_openapi_python.egg-info/requires.txt +2 -0
  12. twitter_openapi_python-0.0.12/twitter_openapi_python/models/base.py +0 -12
  13. twitter_openapi_python-0.0.12/twitter_openapi_python.egg-info/requires.txt +0 -2
  14. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/LICENSE +0 -0
  15. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/LICENSE.AGPL +0 -0
  16. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/README.md +0 -0
  17. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/setup.cfg +0 -0
  18. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/__init__.py +0 -0
  19. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/__init__.py +0 -0
  20. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/default_api.py +0 -0
  21. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/initial_state_api.py +0 -0
  22. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/post_api.py +0 -0
  23. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/tweet_api.py +0 -0
  24. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/user_api.py +0 -0
  25. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/user_list_api.py +0 -0
  26. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/users_api.py +0 -0
  27. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/v11_get_api.py +0 -0
  28. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/api/v11_post_api.py +0 -0
  29. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/models/header.py +0 -0
  30. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/models/initial_state.py +0 -0
  31. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/py.typed +0 -0
  32. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python/utils/__init__.py +0 -0
  33. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python.egg-info/SOURCES.txt +0 -0
  34. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/twitter_openapi_python.egg-info/dependency_links.txt +0 -0
  35. {twitter_openapi_python-0.0.12 → twitter_openapi_python-0.0.15}/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.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
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "twitter_openapi_python"
3
- version = "0.0.12"
3
+ version = "0.0.15"
4
4
  description = "Twitter OpenAPI"
5
5
  authors = ["fa0311 <yuki@yuki0311.com>"]
6
6
  license = "proprietary" # or "AGPL-3.0-only"
@@ -12,9 +12,9 @@ include = ["twitter_openapi_python/py.typed"]
12
12
 
13
13
  [tool.poetry.dependencies]
14
14
  python = "^3.7"
15
- pydantic = "^1.10.5, <2"
15
+ pydantic = ">=2.6"
16
16
 
17
- twitter-openapi-python-generated = "0.0.7"
17
+ twitter-openapi-python-generated = "0.0.11"
18
18
 
19
19
  [tool.poetry.dev-dependencies]
20
20
 
@@ -3,11 +3,11 @@
3
3
  from setuptools import find_packages, setup
4
4
 
5
5
  NAME = "twitter_openapi_python"
6
- VERSION = "0.0.12"
6
+ VERSION = "0.0.15"
7
7
  PYTHON_REQUIRES = ">=3.7"
8
8
  REQUIRES = [
9
- "twitter_openapi_python_generated == 0.0.6",
10
- "pydantic >= 1.10.5, < 2",
9
+ "twitter_openapi_python_generated == 0.0.9",
10
+ "pydantic >= 2.6",
11
11
  ]
12
12
 
13
13
  setup(
@@ -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,
@@ -0,0 +1,9 @@
1
+ from typing import TypeVar
2
+
3
+ from pydantic import BaseModel as PydanticBaseModel
4
+
5
+ T = TypeVar("T")
6
+
7
+
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
@@ -0,0 +1,2 @@
1
+ twitter_openapi_python_generated==0.0.9
2
+ pydantic>=2.6
@@ -1,12 +0,0 @@
1
- from pydantic import BaseModel as PydanticBaseModel
2
- from pydantic.generics import GenericModel as PydanticGenericModel
3
-
4
-
5
- class BaseModel(PydanticBaseModel):
6
- class Config:
7
- arbitrary_types_allowed = True
8
-
9
-
10
- class GenericModel(PydanticGenericModel):
11
- class Config:
12
- arbitrary_types_allowed = True
@@ -1,2 +0,0 @@
1
- twitter_openapi_python_generated==0.0.6
2
- pydantic<2,>=1.10.5