59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import fs from 'fs';
|
|
import axios from 'axios';
|
|
|
|
interface VocabEntry {
|
|
hiragana: string;
|
|
jp: string;
|
|
en: string;
|
|
}
|
|
|
|
interface Group {
|
|
group_name: string;
|
|
words: VocabEntry[];
|
|
}
|
|
|
|
const DECK_NAME = 'Japanese::Lesson 10';
|
|
const MODEL_NAME = 'Basic'; // Update this to match your Anki note type
|
|
const FIELDS = ['Hiragana', 'Kanji', 'English']; // Update to match your note type fields
|
|
|
|
async function addNote(entry: VocabEntry, tags: string[]) {
|
|
try {
|
|
const result = await axios.post('http://localhost:8765', {
|
|
action: 'addNote',
|
|
version: 6,
|
|
params: {
|
|
note: {
|
|
deckName: DECK_NAME,
|
|
modelName: MODEL_NAME,
|
|
fields: {
|
|
[FIELDS[0]]: entry.hiragana,
|
|
[FIELDS[1]]: entry.jp,
|
|
[FIELDS[2]]: entry.en,
|
|
},
|
|
options: {
|
|
allowDuplicate: false,
|
|
},
|
|
tags: tags,
|
|
}
|
|
}
|
|
});
|
|
console.log(`Added: ${entry.hiragana} - ${entry.en}`, result.data);
|
|
} catch (error) {
|
|
console.error(`Failed to add: ${entry.hiragana} - ${entry.en}`, error);
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const raw = fs.readFileSync('./lesson10.json', 'utf-8');
|
|
const vocabList: Group[] = JSON.parse(raw);
|
|
|
|
for (const group of vocabList) {
|
|
const tag = group.group_name.replace(/\s+/g, '_').toLowerCase(); // e.g. "na-adjective" -> "na_adjective"
|
|
for (const word of group.words) {
|
|
await addNote(word, [tag]);
|
|
}
|
|
}
|
|
}
|
|
|
|
main();
|