feat: only decode 200 OK response; filter None from statuses
This commit is contained in:
parent
47e293650c
commit
56ff25e6b6
1 changed files with 8 additions and 5 deletions
13
threads.py
13
threads.py
|
|
@ -100,11 +100,13 @@ def middleware():
|
||||||
async def get(url, session):
|
async def get(url, session):
|
||||||
try:
|
try:
|
||||||
async with session.get(url, ssl=False) as response:
|
async with session.get(url, ssl=False) as response:
|
||||||
res = await response.json()
|
if response.status == 200:
|
||||||
return utils.clean_status(res)
|
res = await response.json()
|
||||||
|
return utils.clean_status(res)
|
||||||
|
else:
|
||||||
|
print(f"No status: {url}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Unable to get url {url} due to {e.__class__}")
|
return None
|
||||||
return {}
|
|
||||||
|
|
||||||
def get_status_url(ser, id):
|
def get_status_url(ser, id):
|
||||||
return f'{ser}/api/v1/statuses/{id}'
|
return f'{ser}/api/v1/statuses/{id}'
|
||||||
|
|
@ -115,7 +117,8 @@ async def fetch_statuses():
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
statuses = await asyncio.gather(*(get(url, session) for url in urls))
|
statuses = await asyncio.gather(*(get(url, session) for url in urls))
|
||||||
return statuses
|
filtered = [x for x in statuses if x is not None]
|
||||||
|
return filtered
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue