Skip to content

Commit

Permalink
split up serialization and assembler logic #7
Browse files Browse the repository at this point in the history
  • Loading branch information
abby.abb committed Nov 25, 2022
1 parent d396b39 commit 1118dcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/deck_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ class DeckAssembler:
def __init__(self):
pass

def assemble_deck_from_codeblocks(self, codeblocks: list[ParsedCodeBlock], output_path: Path):

decks = {}

def add_notes_from_codeblocks(self, codeblocks: list[ParsedCodeBlock], decks: dict):
for codeblock in codeblocks:
note_name = self.get_attribute_from_codeblock_headers(codeblock.headers, "name")

Expand Down Expand Up @@ -39,15 +36,7 @@ def assemble_deck_from_codeblocks(self, codeblocks: list[ParsedCodeBlock], outpu

print(f"Added {note_name} to deck {note_deck_name}")

decks[note_deck_name] = deck

package_name = "deck_package.apkg"

package_path = output_path / package_name

genanki.Package(decks.values()).write_to_file(package_path.absolute())

print(f"Created {package_path.absolute()}")
decks[note_deck_name] = deck

def get_attribute_from_codeblock_headers(self, headers: list[str], header_name: str):
for header in headers:
Expand Down
12 changes: 12 additions & 0 deletions src/markdown_to_anki.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pathlib import Path

import genanki

from deck_assembler import DeckAssembler
from parsed_codeblock import ParsedCodeBlock
from codeblock_parser import CodeblockParser
Expand Down Expand Up @@ -31,6 +33,16 @@ def main():
print(f"Found 'anki' {len(codeblocks)} codeblocks")

assembler.assemble_deck_from_codeblocks(codeblocks, output)

decks = {}

package_name = "deck_package.apkg"

package_path = output / package_name

genanki.Package(decks.values()).write_to_file(package_path.absolute())

print(f"Created {package_path.absolute()}")

if __name__=="__main__":
main()

0 comments on commit 1118dcd

Please sign in to comment.