From dda73bd8e9b670a274e43b3d86ccefd75e71089b Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 22 Dec 2023 12:27:45 +0100 Subject: [PATCH] fix: import all decks --- .../anki_connect/ankiconnect_destination.py | 17 +++++++++-------- .../prompts/base_anki_prompt.py | 2 +- .../prompt_converter/prompts/test_ankiqa.py | 2 +- .../test_ankiconnect_destination.py | 3 ++- .../test_cloze_prompt_extractor.py | 2 +- .../test_qa_prompt_extractor.py | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/ankiconnect_destination.py b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/ankiconnect_destination.py index ed9a8523..fd49cc30 100644 --- a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/ankiconnect_destination.py +++ b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/ankiconnect_destination.py @@ -79,14 +79,14 @@ def _delete_prompts( self.gateway.delete_notes(list(prompt_ids)) def _grouped_cards_to_deck( - self, cards: Mapping[str, Sequence[AnkiCard]] + self, grouped_cards: Mapping[str, Sequence[AnkiCard]] ) -> genanki.Deck: - deck_name = next(iter(cards.keys())) + deck_name = next(iter(grouped_cards.keys())) deck = genanki.Deck( name=deck_name, deck_id=hash_cleaned_str(deck_name) ) - for card in cards[deck_name]: + for card in grouped_cards[deck_name]: deck.add_note(card.to_genanki_note()) # type: ignore return deck @@ -97,11 +97,12 @@ def _create_package( cards_grouped_by_deck = Seq(cards).groupby( lambda card: card.deck ) - decks = ( - Seq([cards_grouped_by_deck]) - .map(self._grouped_cards_to_deck) - .to_list() - ) + decks = [ + self._grouped_cards_to_deck( + {group: cards_grouped_by_deck[group]} + ) + for group in cards_grouped_by_deck + ] return genanki.Package(deck_or_decks=decks) diff --git a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/base_anki_prompt.py b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/base_anki_prompt.py index 97dde3e0..ebc7d6dd 100644 --- a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/base_anki_prompt.py +++ b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/base_anki_prompt.py @@ -26,7 +26,7 @@ def to_genanki_note(self) -> genanki.Note: @property def deck(self) -> str: - deck_prefix = "#anki/deck/" + deck_prefix = "anki/deck/" deck_in_tags = ( tag.replace(deck_prefix, "") for tag in self.tags diff --git a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/test_ankiqa.py b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/test_ankiqa.py index bc656403..2fcd67a9 100644 --- a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/test_ankiqa.py +++ b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/prompt_converter/prompts/test_ankiqa.py @@ -18,5 +18,5 @@ class FakeAnkiQA(AnkiQA): def test_ankiqa_deck_inference(): - card = FakeAnkiQA(tags=["#anki/deck/Subdeck"]) + card = FakeAnkiQA(tags=["anki/deck/Subdeck"]) assert card.deck == "FakeBaseDeck::Subdeck" diff --git a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py index f151b696..02c805c3 100644 --- a/personal_mnemonic_medium/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py +++ b/personal_mnemonic_medium/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py @@ -63,7 +63,7 @@ def test_ankiconnect_push_prompts(): QAWithoutDoc( question="FakeQuestion", answer="FakeAnswer", - add_tags=["#anki/deck/FakeSubdeck"], + add_tags=["anki/deck/FakeSubdeck"], ), ClozeWithoutDoc( text="FakeText", add_tags=["FakeTag"] @@ -83,6 +83,7 @@ def test_ankiconnect_push_prompts(): import_package_command.package.decks[0].name # type: ignore == "FakeDeck::FakeSubdeck" ) + assert len(import_package_command.package.decks) == 2 # type: ignore for command in expected_commands: assert ( diff --git a/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_cloze_prompt_extractor.py b/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_cloze_prompt_extractor.py index e7661b44..e06adfd4 100644 --- a/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_cloze_prompt_extractor.py +++ b/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_cloze_prompt_extractor.py @@ -26,4 +26,4 @@ def test_cloze_prompt_extractor(tmpdir: Path): extractor[0].text == r"What is the meaning of life? {{c734::42}}" ) - assert extractor[0].tags == ["#anki/tag/test_tag"] + assert extractor[0].tags == ["anki/tag/test_tag"] diff --git a/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_qa_prompt_extractor.py b/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_qa_prompt_extractor.py index 7ea1f75e..df0ccf91 100644 --- a/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_qa_prompt_extractor.py +++ b/personal_mnemonic_medium/domain/prompt_source/prompt_extractors/test_qa_prompt_extractor.py @@ -25,5 +25,5 @@ def test_qa_prompt_extractor(tmpdir: Path): prompt = extractor[0] assert prompt.question == "What is the meaning of life?" assert prompt.answer == "42" - assert prompt.tags == ["#anki/tag/test_tag"] + assert prompt.tags == ["anki/tag/test_tag"] assert prompt.uid == 9385242780