Skip to content

Commit ead05f3

Browse files
committed
updated download script to fetch all pages
1 parent 05af874 commit ead05f3

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
},
3232
"devDependencies": {
3333
"@eslint/js": "^9.39.2",
34+
"@leomotors/cli-progress": "^4.0.3",
3435
"@tailwindcss/vite": "^4.1.18",
3536
"@tanstack/eslint-plugin-query": "^5.91.2",
3637
"@tanstack/react-query-devtools": "^5.91.1",

pnpm-lock.yaml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/download.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
import { getUserCollection } from './getUserCollection.ts'
2+
import type { Release } from './types-collection'
23
import fs from 'node:fs'
4+
import { SingleBar, Preset } from '@leomotors/cli-progress'
35

46
const main = async () => {
5-
const vinyls = await getUserCollection({ user: 'davidlyons', perPage: 100 })
6-
fs.writeFileSync('src/lib/vinyls.json', JSON.stringify(vinyls, null, 4))
7-
console.log('Vinyls data written to vinyls.json')
7+
const user = process.argv[2] || 'davidlyons'
8+
let nextPage: number | undefined = 1
9+
let releases: Release[] = []
10+
11+
const bar = new SingleBar(
12+
{
13+
hideCursor: true,
14+
stopOnComplete: true,
15+
gracefulExit: true,
16+
format: 'Fetched page {value} / {total} | {bar}',
17+
},
18+
Preset.shadesClassic
19+
)
20+
21+
while (nextPage) {
22+
const pageData = await getUserCollection({ user, perPage: 100, page: nextPage })
23+
releases = [...releases, ...pageData.releases]
24+
25+
if (nextPage === 1) bar.start(pageData.pagination.pages, 0)
26+
bar.increment()
27+
28+
nextPage = nextPage < pageData.pagination.pages ? nextPage + 1 : undefined
29+
}
30+
31+
const vinyls = {
32+
collectionInfo: {
33+
user: user,
34+
items: releases.length,
35+
},
36+
releases,
37+
}
38+
39+
const file = `src/lib/vinyls.json`
40+
const data = JSON.stringify(vinyls, null, 2)
41+
42+
fs.writeFileSync(file, data)
43+
console.log(`Vinyl collection data written to ${file}`)
844
}
945

1046
main()

0 commit comments

Comments
 (0)