Created
June 17, 2022 00:06
-
-
Save danielphan2003/4893c7fce0dcd4b32f311748b192c36c to your computer and use it in GitHub Desktop.
Get all Wattpad stories in your library, and output it as a single string (useful for automation).
This file contains hidden or 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
| await (async (username) => { | |
| let all_stories = "" | |
| const endpoints = { | |
| "archive": 10, | |
| "library": 25, | |
| } | |
| for (const endpoint in endpoints) { | |
| const url = `https://www.wattpad.com/api/v3/users/${username}/${endpoint}` | |
| const { total } = await (await fetch(`${url}?fields=total`)).json() | |
| const limit = endpoints[endpoint] | |
| let total_accessible = 0 | |
| for (let offset = 0; offset < total; offset += limit) { | |
| setTimeout(100) | |
| const { stories } = await (await fetch(`${url}?offset=${offset == 0 ? 0 : offset + 1}&limit=${limit}&fields=stories(url)`)).json() | |
| for (const story of stories) { | |
| ++total_accessible | |
| all_stories = all_stories + story.url + "\n" | |
| } | |
| } | |
| console.log(all_stories) | |
| console.log(`Total stories from ${endpoint}: ${total}`) | |
| console.log(`Total accessible stories: ${total_accessible}`) | |
| } | |
| }) (wattpad.user.username) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment