2e reviewed manuscript

This commit is contained in:
Luciano Ramalho
2021-11-12 11:33:12 -03:00
parent f5e3cb8ad3
commit 80f7f84274
32 changed files with 323 additions and 156 deletions

View File

@@ -17,15 +17,15 @@ from httpx import AsyncClient # <1>
from flags import BASE_URL, save_flag, main # <2>
async def download_one(session: AsyncClient, cc: str): # <3>
image = await get_flag(session, cc)
async def download_one(client: AsyncClient, cc: str): # <3>
image = await get_flag(client, cc)
save_flag(image, f'{cc}.gif')
print(cc, end=' ', flush=True)
return cc
async def get_flag(session: AsyncClient, cc: str) -> bytes: # <4>
async def get_flag(client: AsyncClient, cc: str) -> bytes: # <4>
url = f'{BASE_URL}/{cc}/{cc}.gif'.lower()
resp = await session.get(url, timeout=6.1,
resp = await client.get(url, timeout=6.1,
follow_redirects=True) # <5>
return resp.read() # <6>
# end::FLAGS_ASYNCIO_TOP[]
@@ -35,8 +35,8 @@ def download_many(cc_list: list[str]) -> int: # <1>
return asyncio.run(supervisor(cc_list)) # <2>
async def supervisor(cc_list: list[str]) -> int:
async with AsyncClient() as session: # <3>
to_do = [download_one(session, cc)
async with AsyncClient() as client: # <3>
to_do = [download_one(client, cc)
for cc in sorted(cc_list)] # <4>
res = await asyncio.gather(*to_do) # <5>