Skip to content

Commit

Permalink
Merge pull request #165 from MartinBernstorff/mb/fix_bind_mounts
Browse files Browse the repository at this point in the history
fix: bind mounts
  • Loading branch information
MartinBernstorff authored Oct 25, 2023
2 parents 7984cd2 + 3d6fded commit 3217d85
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
18 changes: 13 additions & 5 deletions application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -65,16 +72,17 @@ 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,
)

if watch:
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)
5 changes: 4 additions & 1 deletion docker_cmd.sh
Original file line number Diff line number Diff line change
@@ -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
python application/main.py /input/ $HOME/ankidecks --watch
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions src/personal_mnemonic_medium/exporters/anki/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3217d85

Please sign in to comment.