Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions 17-futures/countries/flags_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
from flags import BASE_URL, save_flag, show, main # <2>


@asyncio.coroutine # <3>
def get_flag(cc):
async def get_flag(session, cc):
url = '{}/{cc}/{cc}.gif'.format(BASE_URL, cc=cc.lower())
resp = yield from aiohttp.request('GET', url) # <4>
image = yield from resp.read() # <5>
async with session.get(url) as resp:
image = await resp.read() # <5>
return image


@asyncio.coroutine
def download_one(cc): # <6>
image = yield from get_flag(cc) # <7>
async def download_one(cc): # <6>
async with aiohttp.ClientSession() as session:
image = await get_flag(session, cc) # <7>
show(cc)
save_flag(image, cc.lower() + '.gif')
return cc
Expand Down