chore: extract read percentage
This commit is contained in:
parent
815552ea27
commit
5bd5aede22
2 changed files with 14 additions and 2 deletions
3
.env
3
.env
|
@ -6,4 +6,5 @@ API_APPLE_MUSIC_USER_TOKEN=
|
|||
APPLE_RENEW_TOKEN_URL=
|
||||
SITE_ID_CLICKY=
|
||||
SITE_KEY_CLICKY=
|
||||
SECRET_FEED_ALBUM_RELEASES=
|
||||
SECRET_FEED_ALBUM_RELEASES=
|
||||
COOKIE_STORYGRAPH=
|
|
@ -3,11 +3,16 @@ const { AssetCache } = require('@11ty/eleventy-fetch')
|
|||
const { JSDOM } = jsdom
|
||||
|
||||
module.exports = async function () {
|
||||
const COOKIE = process.env.COOKIE_STORYGRAPH
|
||||
const url = 'https://app.thestorygraph.com/currently-reading/coryd'
|
||||
const asset = new AssetCache('books_data')
|
||||
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
||||
const data = []
|
||||
await fetch(url)
|
||||
await fetch(url, {
|
||||
headers: {
|
||||
Cookie: COOKIE,
|
||||
},
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.then((html) => {
|
||||
const DOM = new JSDOM(html)
|
||||
|
@ -33,6 +38,12 @@ module.exports = async function () {
|
|||
if (!data[index]) data.push({ url: `https://app.thestorygraph.com${url.href}` })
|
||||
if (data[index]) data[index]['url'] = `https://app.thestorygraph.com${url.href}`
|
||||
})
|
||||
doc
|
||||
.querySelectorAll('.md\\:block .progress-tracker-pane .font-semibold')
|
||||
.forEach((percentage, index) => {
|
||||
if (!data[index]) data.push({ percentage: percentage.textContent })
|
||||
if (data[index]) data[index]['percentage'] = percentage.textContent
|
||||
})
|
||||
})
|
||||
const books = data
|
||||
.filter((book) => book.title)
|
||||
|
|
Reference in a new issue