Skip to content

Instantly share code, notes, and snippets.

@fs-c

fs-c/rr-scrape.js

Created Jan 11, 2019
Embed
What would you like to do?
Stupidly basic RR scraping
/* 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
You can’t perform that action at this time.