Extra contents beyond WaniKani
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
1.1 KiB

import fs from 'fs'
import axios from 'axios'
import { IKanji, IRadical } from './shared'
export const subjects = {
data: [] as (IKanji | IRadical)[],
filename: 'wanikani.json',
load() {
this.data = JSON.parse(fs.readFileSync(this.filename, 'utf-8'))
return this.data
},
dump(d: (IKanji | IRadical)[]) {
this.data = d
this.finalize()
},
finalize() {
fs.writeFileSync(this.filename, JSON.stringify(this.data))
}
}
async function main() {
const wk = axios.create({
baseURL: 'https://api.wanikani.com/v2/',
headers: {
Authorization: `Bearer ${process.env['WANIKANI_API_KEY']}`
}
})
const data: (IKanji | IRadical)[] = []
let nextURL = '/subjects?types=radical,kanji'
while (nextURL) {
const r = await wk
.get<{
pages: {
next_url?: string
}
data: (IKanji | IRadical)[]
}>(nextURL)
.then((r) => r.data)
data.push(...r.data)
console.info(r.pages.next_url)
nextURL = r.pages.next_url || ''
}
subjects.dump(data)
}
if (require.main === module) {
main()
}