Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
d60 authored Mar 29, 2024
1 parent 6466b94 commit 339901f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ratelimits.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Rate Limits
<table>
<thead>
<tr>
<th>Endpoint</th>
<th>Limit</th>
<th>Functions</th>
<th>Limit</th>
<th>Endpoint</th>
</tr>
</thead>
<tbody>
Expand Down
2 changes: 1 addition & 1 deletion twikit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
from .user import User
from .utils import build_query

__version__ = '1.3.15'
__version__ = '1.3.16'
13 changes: 12 additions & 1 deletion twikit/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
CouldNotTweet,
TweetNotAvailable,
TwitterException,
UserNotFound,
UserUnavailable,
raise_exceptions_from_response
)
from .group import Group, GroupMessage
Expand Down Expand Up @@ -1102,7 +1104,13 @@ def get_user_by_screen_name(self, screen_name: str) -> User:
params=params,
headers=self._base_headers
).json()

if 'user' not in response['data']:
raise UserNotFound('The user does not exist.')
user_data = response['data']['user']['result']
if user_data.get('__typename') == 'UserUnavailable':
raise UserUnavailable(user_data.get('message'))

return User(self, user_data)

def get_user_by_id(self, user_id: str) -> User:
Expand Down Expand Up @@ -1237,7 +1245,10 @@ def get_tweet_by_id(
continue
tweet_info = tweet_info_[0]

if tweet_info['__typename'] == 'TweetWithVisibilityResults':
if tweet_info.get('__typename') == 'TweetTombstone':
continue

if tweet_info.get('__typename') == 'TweetWithVisibilityResults':
tweet_info = tweet_info['tweet']

user_info = find_dict(tweet_info, 'user_results')[0]['result']
Expand Down
10 changes: 10 additions & 0 deletions twikit/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ class InvalidMedia(TwitterException):
sent with the tweet.
"""

class UserNotFound(TwitterException):
"""
Exception raised when a user does not exsit.
"""

class UserUnavailable(TwitterException):
"""
Exception raised when a user is unavailable.
"""

ERROR_CODE_TO_EXCEPTION: dict[int, TwitterException] = {
187: DuplicateTweet,
324: InvalidMedia
Expand Down
11 changes: 11 additions & 0 deletions twikit/twikit_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
CouldNotTweet,
TweetNotAvailable,
TwitterException,
UserNotFound,
UserUnavailable,
raise_exceptions_from_response
)
from ..utils import (
Expand Down Expand Up @@ -1116,7 +1118,13 @@ async def get_user_by_screen_name(self, screen_name: str) -> User:
params=params,
headers=self._base_headers
)).json()

if 'user' not in response['data']:
raise UserNotFound('The user does not exist.')
user_data = response['data']['user']['result']
if user_data.get('__typename') == 'UserUnavailable':
raise UserUnavailable(user_data.get('message'))

return User(self, user_data)

async def get_user_by_id(self, user_id: str) -> User:
Expand Down Expand Up @@ -1253,6 +1261,9 @@ async def get_tweet_by_id(
continue
tweet_info = tweet_info_[0]

if tweet_info.get('__typename') == 'TweetTombstone':
continue

if tweet_info['__typename'] == 'TweetWithVisibilityResults':
tweet_info = tweet_info['tweet']

Expand Down

0 comments on commit 339901f

Please sign in to comment.