Last active
February 24, 2022 07:54
-
-
Save Zeta611/d3e94f9fa5e5f274a2f73be8c9591c7c to your computer and use it in GitHub Desktop.
[Async downloader] Async file downloader #automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import asyncio | |
async def download(session, url, file): | |
async with session.get(url) as res: | |
with open(file, "wb") as f: | |
f.write(await res.read()) | |
async def main(): | |
links = [ | |
f"https://www.cs.cornell.edu/courses/cs4110/2020fa/lectures/slides{i:02}.pdf" | |
for i in range(1, 36) | |
] + [ | |
f"https://www.cs.cornell.edu/courses/cs4110/2020fa/lectures/lecture{i:02}.pdf" | |
for i in range(1, 31) | |
] | |
async with aiohttp.ClientSession() as session: | |
tasks = [ | |
download(session, link, link.split("/")[-1]) for i, link in enumerate(links) | |
] | |
await asyncio.gather(*tasks) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment