Skip to content

Commit 7099f99

Browse files
committed
fixed index error on login (The bug that prevents logging in has not yet been fixed.)
Fixed a bug in StreamingSession.reconnect. Deleted User.get_likes.
1 parent 37cccd6 commit 7099f99

File tree

5 files changed

+14
-33
lines changed

5 files changed

+14
-33
lines changed

twikit/client/client.py

+10-25
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ def _remove_duplicate_ct0_cookie(self) -> None:
193193
@property
194194
def proxy(self) -> str:
195195
':meta private:'
196-
transport: AsyncHTTPTransport = self.http._mounts.get(
197-
URLPattern('all://')
198-
)
196+
transport: AsyncHTTPTransport = self.http._mounts.get(URLPattern('all://'))
199197
if transport is None:
200198
return None
201199
if not hasattr(transport._pool, '_proxy_url'):
@@ -204,9 +202,7 @@ def proxy(self) -> str:
204202

205203
@proxy.setter
206204
def proxy(self, url: str) -> None:
207-
self.http._mounts = {
208-
URLPattern('all://'): AsyncHTTPTransport(proxy=url)
209-
}
205+
self.http._mounts = {URLPattern('all://'): AsyncHTTPTransport(proxy=url)}
210206

211207
def _get_csrf_token(self) -> str:
212208
"""
@@ -226,11 +222,11 @@ def _base_headers(self) -> dict[str, str]:
226222
Base headers for Twitter API requests.
227223
"""
228224
headers = {
229-
'Authorization': f'Bearer {self._token}',
230-
'Content-Type': 'application/json',
225+
'authorization': f'Bearer {self._token}',
226+
'content-type': 'application/json',
231227
'X-Twitter-Auth-Type': 'OAuth2Session',
232228
'X-Twitter-Active-User': 'yes',
233-
'Referer': 'https://x.com/',
229+
'Referer': 'https://twitter.com/',
234230
'User-Agent': self._user_agent,
235231
}
236232

@@ -251,9 +247,7 @@ async def _get_guest_token(self) -> str:
251247
return guest_token
252248

253249
async def _ui_metrix(self) -> str:
254-
js, _ = await self.get(
255-
'https://twitter.com/i/js_inst?c_name=ui_metrics'
256-
)
250+
js, _ = await self.get('https://twitter.com/i/js_inst?c_name=ui_metrics')
257251
return re.findall(r'return ({.*?});', js, re.DOTALL)[0]
258252

259253
async def login(
@@ -985,9 +979,7 @@ async def upload_media(
985979
while bytes_sent < total_bytes:
986980
chunk = binary[bytes_sent:bytes_sent + MAX_SEGMENT_SIZE]
987981
chunk_stream = io.BytesIO(chunk)
988-
coro = self.v11.upload_media_append(
989-
is_long_video, media_id, segment_index, chunk_stream
990-
)
982+
coro = self.v11.upload_media_append(is_long_video, media_id, segment_index, chunk_stream)
991983
append_tasks.append(asyncio.create_task(coro))
992984
chunk_streams.append(chunk_stream)
993985

@@ -1130,8 +1122,7 @@ async def vote(
11301122
:class:`Poll`
11311123
The Poll object representing the updated poll after voting.
11321124
"""
1133-
response, _ = await self.v11.vote(selected_choice, card_uri,
1134-
tweet_id, card_name)
1125+
response, _ = await self.v11.vote(selected_choice, card_uri, tweet_id, card_name)
11351126
card_data = {
11361127
'rest_id': response['card']['url'],
11371128
'legacy': response['card']
@@ -1240,16 +1231,13 @@ async def create_tweet(
12401231
reply_to, attachment_url, community_id, share_with_followers,
12411232
richtext_options, edit_tweet_id, limit_mode
12421233
)
1243-
_result = find_dict(response, 'result', find_one=True)
1234+
_result = response['data']['create_tweet']['tweet_results']
12441235
if not _result:
12451236
raise_exceptions_from_response(response['errors'])
12461237
raise CouldNotTweet(
12471238
response['errors'][0] if response['errors'] else 'Failed to post a tweet.'
12481239
)
1249-
1250-
tweet_info = _result[0]
1251-
user_info = tweet_info['core']['user_results']['result']
1252-
return Tweet(self, tweet_info, User(self, user_info))
1240+
return tweet_from_data(self, _result)
12531241

12541242
async def create_scheduled_tweet(
12551243
self,
@@ -2605,9 +2593,6 @@ async def _get_user_friendship_2(
26052593
count: int, f, cursor: str
26062594
) -> Result[User]:
26072595
response, _ = await f(user_id, screen_name, count, cursor)
2608-
from jlog import log
2609-
log(response)
2610-
26112596
users = response['users']
26122597
results = []
26132598
for user in users:

twikit/community.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class Community:
9090
Indicates if the community is pinned.
9191
rules : list[:class:`CommunityRule`]
9292
The rules of the community.
93-
9493
"""
94+
9595
def __init__(self, client: Client, data: dict) -> None:
9696
self._client = client
9797
self.id: str = data['rest_id']

twikit/guest/client.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ async def activate(self) -> str:
183183
"""
184184
Activate the client by generating a guest token.
185185
"""
186-
if self._guest_token is None:
187-
response, _ = await self.v11.guest_activate()
188-
self._guest_token = response['guest_token']
186+
response, _ = await self.v11.guest_activate()
187+
self._guest_token = response['guest_token']
189188
return self._guest_token
190189

191190
async def get_user_by_screen_name(self, screen_name: str) -> User:

twikit/streaming.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def reconnect(self) -> tuple[str, Payload]:
3535
"""
3636
Reconnects the session.
3737
"""
38-
stream = await self._client._stream(self.topics)
38+
stream = self._client._stream(self.topics)
3939
config_event = await anext(stream)
4040
self.id = config_event[1].config.session_id
4141
self._stream = stream

twikit/user.py

-3
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ async def get_tweets(
169169
"""
170170
return await self._client.get_user_tweets(self.id, tweet_type, count)
171171

172-
async def get_likes(self, count: int = 40, cursor: str | None = None) -> Result[Tweet]:
173-
return await self._client.get_user_likes(self.id, count=count, cursor=cursor)
174-
175172
async def follow(self) -> Response:
176173
"""
177174
Follows the user.

0 commit comments

Comments
 (0)