diff --git a/memium/core.py b/memium/core.py index 9a4de64c..4c6956cc 100644 --- a/memium/core.py +++ b/memium/core.py @@ -20,30 +20,35 @@ def main( dry_run: bool, push_all: bool = False, ): - source_prompts = DocumentPromptSource( - document_ingester=MarkdownDocumentSource(directory=input_dir), - prompt_extractors=[ - QAPromptExtractor(question_prefix="Q.", answer_prefix="A."), - TableExtractor(), - ], - ).get_prompts() + # Setup gateway as first step. If Anki is not running, no need to parse all the prompts. + gateway = AnkiConnectGateway( + ankiconnect_url=ANKICONNECT_URL, + base_deck=base_deck, + tmp_read_dir=host_input_dir() if in_docker() else input_dir, + tmp_write_dir=input_dir, + max_deletions_per_run=max_deletions_per_run, + max_wait_seconds=3600, + ) dest_class = AnkiConnectDestination if not dry_run else DryRunDestination destination = dest_class( - gateway=AnkiConnectGateway( - ankiconnect_url=ANKICONNECT_URL, - base_deck=base_deck, - tmp_read_dir=host_input_dir() if in_docker() else input_dir, - tmp_write_dir=input_dir, - max_deletions_per_run=max_deletions_per_run, - max_wait_seconds=30, - ), + gateway=gateway, prompt_converter=AnkiPromptConverter( base_deck=base_deck, card_css=Path("memium/destination/ankiconnect/default_styling.css").read_text(), ), ) + # Get the inputs + source_prompts = DocumentPromptSource( + document_ingester=MarkdownDocumentSource(directory=input_dir), + prompt_extractors=[ + QAPromptExtractor(question_prefix="Q.", answer_prefix="A."), + TableExtractor(), + ], + ).get_prompts() + + # Get the updates update_commands = ( [PushPrompts(prompts=source_prompts)] if push_all @@ -51,5 +56,6 @@ def main( source_prompts=source_prompts, destination_prompts=destination.get_all_prompts() ) ) + # Send them destination.update(commands=update_commands) diff --git a/memium/destination/ankiconnect/ankiconnect_gateway.py b/memium/destination/ankiconnect/ankiconnect_gateway.py index b67bb0cf..7c219b03 100644 --- a/memium/destination/ankiconnect/ankiconnect_gateway.py +++ b/memium/destination/ankiconnect/ankiconnect_gateway.py @@ -80,10 +80,10 @@ def __post_init__(self) -> None: if seconds_waited >= self.max_wait_seconds: raise ConnectionError(f"Could not connect to AnkiConnect at {self.ankiconnect_url}") - wait_seconds = 2 - log.info(f"AnkiConnect is not live, waiting {wait_seconds} seconds...") - seconds_waited += wait_seconds - sleep(wait_seconds) + poll_seconds = 10 + log.info(f"AnkiConnect is not live, waiting {poll_seconds} seconds...") + seconds_waited += poll_seconds + sleep(poll_seconds) def update_model(self, model: genanki.Model) -> None: existing_model_names = self._invoke(AnkiConnectCommand.GET_MODEL_NAMES) diff --git a/uv.lock b/uv.lock index b56f57c2..638705ca 100644 --- a/uv.lock +++ b/uv.lock @@ -570,7 +570,7 @@ wheels = [ [[package]] name = "memium" -version = "0.25.0" +version = "0.25.1" source = { editable = "." } dependencies = [ { name = "bs4" },