basic flags example with async/await
This commit is contained in:
parent
a16bd835d2
commit
22cfc8d6dd
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
concurrency/flags/img/*.gif
|
||||
concurrency/charfinder/charfinder_index.pickle
|
||||
18-asyncio/charfinder/charfinder_index.pickle
|
||||
|
@ -17,17 +17,15 @@ import aiohttp # <1>
|
||||
from flags import BASE_URL, save_flag, show, main # <2>
|
||||
|
||||
|
||||
@asyncio.coroutine # <3>
|
||||
def get_flag(cc):
|
||||
async def get_flag(cc): # <3>
|
||||
url = '{}/{cc}/{cc}.gif'.format(BASE_URL, cc=cc.lower())
|
||||
resp = yield from aiohttp.request('GET', url) # <4>
|
||||
image = yield from resp.read() # <5>
|
||||
resp = await aiohttp.request('GET', url) # <4>
|
||||
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>
|
||||
image = await get_flag(cc) # <7>
|
||||
show(cc)
|
||||
save_flag(image, cc.lower() + '.gif')
|
||||
return cc
|
||||
|
Loading…
Reference in New Issue
Block a user