Skip to content

Commit

Permalink
X redirects to x.com (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
travislee89 committed May 17, 2024
1 parent 117b4f7 commit bfb7c4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, connections=20, retries=5):
self.default_header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Mac OS X 10_15_7) '
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'}
self.twitter_set = {'twitter.com', 'www.twitter.com', 'mobile.twitter.com', 'x.com', 'www.x.com'}
self.x_set = {'x.com', 'www.x.com'}
limits = httpx.Limits(max_connections=connections * 2, max_keepalive_connections=connections)
http_transport = httpx.AsyncHTTPTransport(http2=True, retries=retries, verify=False, limits=limits)

Expand Down Expand Up @@ -52,6 +53,10 @@ async def url_get_redirect(self, url: str, max_times: int) -> str:
if x > 5:
return url

url_parse = urlparse(url)
if url_parse.hostname in self.x_set:
return url

response = await self.session.get(url, follow_redirects=False)
if response.status_code in (301, 302, 303, 307, 308):
if response.headers.get('Location') and not response.headers.get('Location').startswith('http'):
Expand Down
2 changes: 1 addition & 1 deletion lib/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

version = '0.2.10'
version = '0.2.11'
message = ('*Tweet forward Bot*',
f'Version: {version}\n',
'*Usage:*',
Expand Down

0 comments on commit bfb7c4b

Please sign in to comment.