mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-28 02:32:11 +10:00
30 lines
798 B
TypeScript
30 lines
798 B
TypeScript
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 })
|