Compare commits
1 Commits
main
...
feature/ge
Author | SHA1 | Date |
---|---|---|
gabriel becker | 72c9dae6b4 | 2 years ago |
6 changed files with 70 additions and 11 deletions
@ -1,5 +1,6 @@
|
||||
click |
||||
genanki |
||||
pandas |
||||
pandas==1.5.2 |
||||
pyyaml |
||||
bullet |
||||
translate |
@ -0,0 +1,17 @@
|
||||
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 |
@ -0,0 +1,28 @@
|
||||
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