55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import vocabList from './L11.json';
|
|
import axios from 'axios';
|
|
|
|
interface VocabEntry {
|
|
hiragana: string;
|
|
jp: string;
|
|
en: string;
|
|
}
|
|
|
|
const DECK_NAME = 'JAPN 110';
|
|
const MODEL_NAME = 'Basic'; // Make sure this matches your Anki note type
|
|
const FIELDS = ['Front', 'Back'] as const;
|
|
|
|
async function addNote(entry: VocabEntry, tags: string[]) {
|
|
try {
|
|
const front = entry.jp.trim() || entry.hiragana.trim();
|
|
const result = await axios.post('http://localhost:8765', {
|
|
action: 'addNote',
|
|
version: 6,
|
|
params: {
|
|
note: {
|
|
deckName: DECK_NAME,
|
|
modelName: MODEL_NAME,
|
|
fields: {
|
|
[FIELDS[0]]: front,
|
|
[FIELDS[1]]: `${entry.hiragana}\n${entry.en}`,
|
|
},
|
|
options: {
|
|
allowDuplicate: false,
|
|
},
|
|
tags: tags,
|
|
}
|
|
}
|
|
});
|
|
if (result?.data?.result === null){
|
|
console.error(`Failed to add: ${front} - ${entry.en}`, result.data.error);
|
|
} else {
|
|
console.log(`Added: ${front} - ${entry.en}`);
|
|
}
|
|
} catch (error) {
|
|
console.error(`Failed to add: ${entry.jp} - ${entry.en}`, error);
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
for (const group of vocabList) {
|
|
const tag = "Vocabulary::" + group.group_name;
|
|
for (const word of group.words) {
|
|
await addNote(word, [tag, "Vocabulary::L11"]);
|
|
}
|
|
}
|
|
}
|
|
|
|
main();
|