Last active
April 1, 2021 21:58
-
-
Save dmdboi/8a86e733f5536d92090800961db33e90 to your computer and use it in GitHub Desktop.
Downloads the JSON data for a given number of XKCD comics
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
const axios = require('axios') | |
const fs = require('fs'); | |
const start = async (number) => { | |
for (let num = 0; num < 10; num++) { | |
let posts = [] | |
for (let index = 0; index < number; index++) { | |
let comic = (num * number) + index + 1 | |
console.log(comic) | |
try { | |
let response = await axios.get(`https://xkcd.com/${comic}/info.0.json`) | |
posts.push(response.data) | |
} catch(error) { | |
continue; | |
} | |
} | |
fs.writeFileSync(`xkcd_${num}.json`, JSON.stringify(posts), 'utf8'); | |
} | |
} | |
//Number of comics to get per file | |
start(100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment