Skip to content

Instantly share code, notes, and snippets.

@fs-c
Created January 11, 2019 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fs-c/9bf5cb88be19f3acd673bf2708700105 to your computer and use it in GitHub Desktop.
Save fs-c/9bf5cb88be19f3acd673bf2708700105 to your computer and use it in GitHub Desktop.
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