Skip to content

Instantly share code, notes, and snippets.

@danielphan2003
Created June 17, 2022 00:06
Show Gist options
  • Save danielphan2003/4893c7fce0dcd4b32f311748b192c36c to your computer and use it in GitHub Desktop.
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).
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