mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-28 02:32:11 +10:00
chore: update public repo
This commit is contained in:
parent
c118bcbfc3
commit
f02ccb6029
12 changed files with 510 additions and 2 deletions
30
scripts/misc/shikimori/bans.ts
Normal file
30
scripts/misc/shikimori/bans.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { asyncPool } from '@fuman/utils'
|
||||
import Database from 'better-sqlite3'
|
||||
import { counterIter, ffetchShiki } from './utils.ts'
|
||||
|
||||
const db = new Database('assets/shikimori.db')
|
||||
db.exec(`
|
||||
create table if not exists bans (
|
||||
id integer primary key,
|
||||
data text not null
|
||||
);
|
||||
`)
|
||||
|
||||
const insertQuery = db.prepare('insert into bans (id, data) values (?, ?) on conflict (id) do update set data = excluded.data')
|
||||
|
||||
const counter = counterIter(1)
|
||||
|
||||
await asyncPool(counter.iter, async (page) => {
|
||||
if (page % 100 === 0) {
|
||||
console.log('currently at page %d', page)
|
||||
}
|
||||
const data = await ffetchShiki(`/api/bans?page=${page}`).json<any>()
|
||||
if (!data.length) {
|
||||
counter.end()
|
||||
return
|
||||
}
|
||||
|
||||
for (const ban of data) {
|
||||
insertQuery.run(ban.id, JSON.stringify(ban))
|
||||
}
|
||||
}, { limit: 64 })
|
Loading…
Add table
Add a link
Reference in a new issue