Compare commits
No commits in common. 'feature/get-translations' and 'main' have entirely different histories.
feature/ge
...
main
6 changed files with 11 additions and 70 deletions
@ -1,6 +1,5 @@ |
|||||||
click |
click |
||||||
genanki |
genanki |
||||||
pandas==1.5.2 |
pandas |
||||||
pyyaml |
pyyaml |
||||||
bullet |
bullet |
||||||
translate |
|
@ -1,17 +0,0 @@ |
|||||||
import genanki |
|
||||||
from typing import Collection, List |
|
||||||
|
|
||||||
from ankimaker import generator |
|
||||||
|
|
||||||
|
|
||||||
class QuestionAnswerGenerator: |
|
||||||
def __init__(self): |
|
||||||
self.__model = generator.create_model() |
|
||||||
|
|
||||||
def get_cards(self, questions: Collection[str], answers: Collection[str]) -> List[genanki.Model]: |
|
||||||
assert len(questions) == len(answers) |
|
||||||
cards = list() |
|
||||||
for content_fields in zip(questions, answers): |
|
||||||
card = generator.create_note(self.__model, fields=content_fields) |
|
||||||
cards.append(card) |
|
||||||
return cards |
|
@ -1,28 +0,0 @@ |
|||||||
import genanki |
|
||||||
from translate import Translator |
|
||||||
from typing import Collection, List |
|
||||||
|
|
||||||
from ankimaker import generator |
|
||||||
|
|
||||||
|
|
||||||
class TranslatorGenerator: |
|
||||||
def __init__(self, original_language, destination_language): |
|
||||||
""" |
|
||||||
:param original_language: Language of the inserted text, following https://en.wikipedia.org/wiki/ISO_639-1 |
|
||||||
:param destination_language: Language you want to translate to, following https://en.wikipedia.org/wiki/ISO_639-1 |
|
||||||
""" |
|
||||||
self.__translator = Translator(from_lang=original_language, to_lang=destination_language) |
|
||||||
self.__model = generator.model.create_model() |
|
||||||
|
|
||||||
def get_cards(self, content_collection: Collection[str]) -> List[genanki.Model]: |
|
||||||
cards = list() |
|
||||||
for content in content_collection: |
|
||||||
card = self._create_card(content) |
|
||||||
cards.append(card) |
|
||||||
return cards |
|
||||||
|
|
||||||
def _create_card(self, content): |
|
||||||
translation = self.__translator.translate(content) |
|
||||||
fields = (content, translation) |
|
||||||
card = generator.create_note(self.__model, fields) |
|
||||||
return card |
|
Loading…
Reference in new issue