Skip to content

Instantly share code, notes, and snippets.

@Zeta611
Last active February 24, 2022 07:54
Show Gist options
  • Save Zeta611/d3e94f9fa5e5f274a2f73be8c9591c7c to your computer and use it in GitHub Desktop.
Save Zeta611/d3e94f9fa5e5f274a2f73be8c9591c7c to your computer and use it in GitHub Desktop.
[Async downloader] Async file downloader #automation
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