Skip to content

Commit

Permalink
Merge pull request #146 from MerleLiuKun/fix-ratelimit
Browse files Browse the repository at this point in the history
fix(ratelimit): 🐛 fix limit for by username
  • Loading branch information
MerleLiuKun authored Nov 21, 2023
2 parents d1cea37 + 8c8b7da commit 1a069ce
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pytwitter/rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def get_limit(self, auth_type, method="GET"):
LIMIT_USER_GET=900,
)
USER_BY_USERNAME = Endpoint(
resource="/users/by/:username",
regex=re.compile(r"/users/by/\w+"),
resource="/users/by/username/:username",
regex=re.compile(r"/users/by/username/\w+"),
LIMIT_APP_GET=300,
LIMIT_USER_GET=900,
)
Expand Down Expand Up @@ -357,6 +357,11 @@ def get_limit(self, auth_type, method="GET"):
regex=re.compile(r"/dm_conversations"),
LIMIT_APP_GET=200,
)
MEDIA_UPLOAD = Endpoint(
resource="/media/upload.json",
regex=re.compile(r"/media/upload.json"),
LIMIT_USER_POST=415,
)

PATH_VAR_ENDPOINTS = [
TWEET_BY_ID,
Expand Down Expand Up @@ -413,6 +418,7 @@ def get_limit(self, auth_type, method="GET"):
DM_MESSAGE_TO_PARTICIPANT,
DM_MESSAGE_TO_CONVERSATION,
DM_CONVERSATIONS,
MEDIA_UPLOAD,
]


Expand Down Expand Up @@ -440,7 +446,9 @@ def __init__(self, auth_type="app"):

@staticmethod
def url_to_endpoint(url) -> Endpoint:
resource = urlparse(url).path.replace("/2", "", 1) # only replace api version
resource = (
urlparse(url).path.replace("/2", "", 1).replace("/1.1", "", 1)
) # only replace api version
for endpoint in PATH_VAR_ENDPOINTS:
if re.fullmatch(endpoint.regex, resource):
return endpoint
Expand Down

0 comments on commit 1a069ce

Please sign in to comment.