diff --git a/application/main.py b/application/main.py index 87d01d39..5a110106 100644 --- a/application/main.py +++ b/application/main.py @@ -26,13 +26,20 @@ def request(action: Any, **params: Any) -> Dict[str, Any]: def main( - recur_dir: Path, + input_dir: Path, + host_output_dir: Path, watch: Annotated[ bool, typer.Option(help="Keep running, updating Anki deck every 15 seconds"), ], ): """Run the thing.""" + if not input_dir.exists(): + raise FileNotFoundError(f"Input directory {input_dir} does not exist") + + if not host_output_dir.exists(): + msg.info(f"Creating output directory {host_output_dir}") + host_output_dir.mkdir(parents=True, exist_ok=True) sentry_sdk.init( dsn="https://37f17d6aa7742424652663a04154e032@o4506053997166592.ingest.sentry.io/4506053999984640", @@ -53,7 +60,7 @@ def main( ], card_exporter=AnkiPackageGenerator(), # Step 3, get the cards from the prompts ).run( - input_path=recur_dir, + input_path=input_dir, ) decks = defaultdict(list) @@ -65,7 +72,8 @@ def main( deck_bundle = AnkiPackageGenerator().cards_to_deck_bundle(cards=decks[deck]) sync_deck( deck_bundle=deck_bundle, - dir_path=Path(__file__).parent, + sync_dir_path=host_output_dir, + save_dir_path=Path("/output"), max_wait_for_ankiconnect=30, ) @@ -73,8 +81,8 @@ def main( sleep_seconds = 60 msg.good(f"Sync complete, sleeping for {sleep_seconds} seconds") sleep(sleep_seconds) - main(recur_dir=recur_dir, watch=watch) - + main(input_dir=input_dir, watch=watch, host_output_dir=host_output_dir) + if __name__ == "__main__": typer.run(main) diff --git a/docker_cmd.sh b/docker_cmd.sh index 4d137cf1..5061a082 100755 --- a/docker_cmd.sh +++ b/docker_cmd.sh @@ -1,7 +1,10 @@ docker build . -t personal-mnemonic-medium -f Dockerfile +docker volume create ankidecks + docker run -itd \ -v $HOME/Library/Mobile\ Documents/iCloud~md~obsidian/Documents/Life\ Lessons\ iCloud/:/input \ + -v $HOME/ankidecks:/output \ --restart unless-stopped \ personal-mnemonic-medium \ - python application/main.py /input/ Life.apkg --watch \ No newline at end of file + python application/main.py /input/ $HOME/ankidecks --watch \ No newline at end of file diff --git a/makefile b/makefile index c5232d66..a547efa1 100644 --- a/makefile +++ b/makefile @@ -22,7 +22,7 @@ validate: @make lint && make type-check && make test pr: + gh pr create -w make validate git push - gh pr create gh pr merge --auto --merge \ No newline at end of file diff --git a/src/personal_mnemonic_medium/exporters/anki/sync.py b/src/personal_mnemonic_medium/exporters/anki/sync.py index 4cc6e0c2..33cbc213 100644 --- a/src/personal_mnemonic_medium/exporters/anki/sync.py +++ b/src/personal_mnemonic_medium/exporters/anki/sync.py @@ -63,7 +63,8 @@ def anki_connect_is_live() -> bool: # Borrowed from https://github.com/lukesmurray/markdown-anki-decks/blob/de6556d7ecd2d39335607c05171f8a9c39c8f422/markdown_anki_decks/sync.py#L64 def sync_deck( deck_bundle: DeckBundle, - dir_path: Path, + save_dir_path: Path, + sync_dir_path: Path, delete_cards: bool = True, max_wait_for_ankiconnect: int = 30, ): @@ -101,9 +102,10 @@ def sync_deck( msg.info("\tNotes removed: ") msg.info(f"\t\t{removed_note_guids}") - package_path = deck_bundle.save_deck_to_file(dir_path / "deck.apkg") + package_path = deck_bundle.save_deck_to_file(save_dir_path / "deck.apkg") try: - invoke("importPackage", path=str(package_path)) + sync_path = str(sync_dir_path / "deck.apkg") + invoke("importPackage", path=sync_path) print(f"Imported {deck_bundle.deck.name}!") if delete_cards: