adds support for comppleted files
This commit is contained in:
@@ -13,7 +13,13 @@ from pinyin_tone_converter.pinyin_tone_converter import PinyinToneConverter
|
||||
|
||||
# Local
|
||||
from .constants import DICTATION_TYPE, DICT_TYPE, PHRASES_TYPE
|
||||
from .utility import DictionaryResult, ProcessFile, ProcessFolder, TranslationResult
|
||||
from .utility import (
|
||||
DictionaryResult,
|
||||
ProcessFile,
|
||||
ProcessFolder,
|
||||
SimpleResult,
|
||||
TranslationResult,
|
||||
)
|
||||
|
||||
# Constants
|
||||
|
||||
@@ -137,9 +143,86 @@ HSK_MODEL = Model(
|
||||
css=CSS,
|
||||
)
|
||||
|
||||
SIMPLE_HSK_MODEL = Model(
|
||||
2819647620,
|
||||
"Simple HSK Model",
|
||||
fields=[
|
||||
{"name": "Meaning"},
|
||||
{"name": "Pinyin"},
|
||||
{"name": "Simplified"},
|
||||
{"name": "Audio"},
|
||||
],
|
||||
templates=[
|
||||
{
|
||||
"name": "Card 1",
|
||||
"qfmt": (
|
||||
"<strong>{{Pinyin}}</strong>"
|
||||
"<br>{{Meaning}}"
|
||||
"<br>{{Audio}}"
|
||||
"<br>Simplified: {{type:Simplified}}"
|
||||
),
|
||||
"afmt": (
|
||||
"{{FrontSide}}<hr id='answer''><div class='simple'>{{Simplified}}</div>"
|
||||
),
|
||||
},
|
||||
{
|
||||
"name": "Card 2",
|
||||
"qfmt": (
|
||||
"<div class='simple'>{{Simplified}}</div>" "<br>Pinyin: {{type:Pinyin}}"
|
||||
),
|
||||
"afmt": (
|
||||
"{{FrontSide}}<hr id='answer'><strong>{{Pinyin}}</strong>"
|
||||
"<br>{{Meaning}}<br>{{Audio}}"
|
||||
),
|
||||
},
|
||||
{
|
||||
"name": "Card 3",
|
||||
"qfmt": ("{{Audio}}" "<br>Simplified: {{type:Simplified}}"),
|
||||
"afmt": (
|
||||
"{{FrontSide}}<hr id='answer'><strong>{{Pinyin}}</strong>"
|
||||
"<br><div class='simple'>{{Simplified}}</div>"
|
||||
),
|
||||
},
|
||||
],
|
||||
css=CSS,
|
||||
)
|
||||
|
||||
# Proccess
|
||||
|
||||
|
||||
def output_anki_completed(
|
||||
process_file: ProcessFile, results: list[SimpleResult]
|
||||
) -> Path:
|
||||
"""Creates an anki file for a completed file"""
|
||||
final_file = (
|
||||
process_file.output_name.parent / f"{process_file.input_file.stem}.apkg"
|
||||
)
|
||||
deck_name = "::".join(process_file.input_file.parts[:-1] + (final_file.stem,))
|
||||
deck = Deck(
|
||||
random.randrange(1 << 30, 1 << 31),
|
||||
deck_name,
|
||||
f"Deck for {process_file.input_file.stem}, "
|
||||
"created in https://www.wolfang.info.ve/hskankicreator/",
|
||||
)
|
||||
audios = []
|
||||
for result in results:
|
||||
note = Note(
|
||||
model=SIMPLE_HSK_MODEL,
|
||||
fields=[
|
||||
result.meaning,
|
||||
PinyinToneConverter().convert_text(result.pinyin),
|
||||
result.character,
|
||||
f"[sound:{result.audio_path.name}]",
|
||||
],
|
||||
)
|
||||
deck.add_note(note)
|
||||
audios.append(result.audio_path)
|
||||
package = Package(deck)
|
||||
package.media_files = audios
|
||||
package.write_to_file(final_file)
|
||||
return final_file
|
||||
|
||||
|
||||
def output_anki_dictation(
|
||||
process_file: ProcessFile, results: list[DictionaryResult]
|
||||
) -> Path:
|
||||
|
||||
Reference in New Issue
Block a user