Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import aiohttp
- LINK_FILE = open('links.txt', 'r')
- LINKS = LINK_FILE.readlines()
- LINKS_COUNT = len(LINKS)
- async def download_coroutine(img_url):
- global LINKS_COUNT
- async with aiohttp.ClientSession() as session:
- async with session.get(img_url) as resp:
- while True:
- chunk = await resp.content.read(1024 * 64)
- if not chunk:
- break
- # writing chunk to file is unnecessary for a benchmark
- LINKS_COUNT -= 1
- print(f'\rImages left: {LINKS_COUNT} ', end='')
- async def main():
- await asyncio.wait([download_coroutine(img_url.strip()) for img_url in LINKS])
- if __name__ == '__main__':
- loop = asyncio.get_event_loop()
- loop.run_until_complete(main())
- loop.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement