Created
April 28, 2020 00:21
-
-
Save delivrance/42032b581df38092dcd5c69cf07b0fd6 to your computer and use it in GitHub Desktop.
Download all available xkcd comics metadata as json list
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 asyncio | |
import aiohttp | |
import json | |
async def main(): | |
async with aiohttp.ClientSession() as session: | |
n = (await (await session.get("https://xkcd.com/info.0.json")).json())["num"] | |
with open("xkcd.json", "w") as f: | |
f.write(json.dumps([ | |
c for c in await asyncio.gather(*[ | |
r.json() | |
for r in await asyncio.gather(*[ | |
session.get(f"https://xkcd.com/{i}/info.0.json") | |
for i in range(1, n + 1) | |
if i not in [404] | |
]) | |
]) | |
], indent=4)) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment