Created
January 11, 2019 20:28
-
-
Save fs-c/9bf5cb88be19f3acd673bf2708700105 to your computer and use it in GitHub Desktop.
Stupidly basic RR scraping
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
/* This is probably breaking RR rules or something. | |
* I didn't test this but it should work. | |
*/ | |
const { writeFileSync } = require('fs'); | |
const { RoyalRoadAPI } = require('@l1lly/royalroadl-api'); | |
const api = new RoyalRoadAPI(); | |
const args = process.argv.splice(2); | |
const chapter = parseInt(args[0], 10); | |
const max = parseInt(args[1], 10) || 5; | |
if (!chapter) { | |
console.log('usage: node rrl-scrape.js <chapter ID> [<max chapters>]'); | |
return 1; | |
} | |
(async () => { | |
let remaining = max; | |
let current = chapter; | |
while (remaining-- && current != -1) { | |
const { data } = await api.chapter.getChapter(current); | |
writeFileSync(`chapter-${current}.json`, JSON.stringify(data)); | |
current = data.next; | |
} | |
})().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment