mirror of
https://github.com/Xtao-Labs/twitter2telegram.git
synced 2024-11-30 19:31:57 +00:00
feat: retry 3 times in one host
This commit is contained in:
parent
b9ad65b01b
commit
7765f33700
17
defs/feed.py
17
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 UsernameNotFound
|
||||||
raise HostNeedChange
|
raise HostNeedChange
|
||||||
else:
|
|
||||||
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