mirror of
https://github.com/Xtao-Labs/twitter2telegram.git
synced 2024-11-27 18:41:17 +00:00
feat: retry 3 times in one host
This commit is contained in:
parent
b9ad65b01b
commit
7765f33700
19
defs/feed.py
19
defs/feed.py
@ -18,15 +18,28 @@ class HostNeedChange(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def retry(func):
|
||||||
|
async def wrapper(*args, **kwargs):
|
||||||
|
for i in range(3):
|
||||||
|
try:
|
||||||
|
return await func(*args, **kwargs)
|
||||||
|
except HostNeedChange:
|
||||||
|
if i == 2:
|
||||||
|
raise HostNeedChange
|
||||||
|
continue
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@retry
|
||||||
async def get(username: str, host: str) -> Optional[FeedParserDict]:
|
async def get(username: str, host: str) -> Optional[FeedParserDict]:
|
||||||
url = f"{host}/twitter/user/{username}"
|
url = f"{host}/twitter/user/{username}"
|
||||||
response = await request.get(url)
|
response = await request.get(url)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return parse(response.text)
|
return parse(response.text)
|
||||||
elif response.status_code == 404:
|
elif response.status_code == 404:
|
||||||
raise HostNeedChange
|
raise UsernameNotFound
|
||||||
else:
|
raise HostNeedChange
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
async def parse_tweets(data: List[FeedParserDict]) -> List[Tweet]:
|
async def parse_tweets(data: List[FeedParserDict]) -> List[Tweet]:
|
||||||
|
Loading…
Reference in New Issue
Block a user