Last active
November 4, 2024 05:12
-
-
Save khajavi/a9ee53a1bd01140bd2f89095281ceaca to your computer and use it in GitHub Desktop.
Revisions
-
khajavi revised this gist
Nov 4, 2024 . No changes.There are no files selected for viewing
-
khajavi revised this gist
Nov 4, 2024 . No changes.There are no files selected for viewing
-
khajavi created this gist
Nov 4, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ - sentence: "The weather is sort of chilly, but it's not too cold for a walk." explanation: "This sentence uses 'sort of' to mean it’s a bit chilly but not very cold." - sentence: "I sort of understand the concept, but I need more practice." explanation: "Here, 'sort of' implies partial understanding but a need for more clarity." This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ import genanki import yaml import glob import os # Define paths EXAMPLES_DIR = './examples/' # Directory where the example YAML files are stored OUTPUT_FILE = 'learn_english_by_example.apkg' # Output file name for the Anki package # Create a model (the format of the cards) model_id = 1607392320 deck_name = "Learn English By Example" anki_model = genanki.Model( model_id, deck_name, fields=[ {'name': 'Sentence'}, {'name': 'Explanation'}, ], templates=[ { 'name': 'Card 1', 'qfmt': '{{Sentence}}', 'afmt': '{{FrontSide}}<hr id="answer">{{Explanation}}', }, ]) # Create a new deck deck_id = 2059400111 anki_deck = genanki.Deck(deck_id,deck_name) # Function to load examples from YAML files in the specified directory def load_examples_from_directory(directory): examples = [] for filepath in glob.glob(os.path.join(directory, '*.yaml')): with open(filepath, 'r') as file: file_examples = yaml.safe_load(file) examples.extend(file_examples) return examples # Load all examples from files in the directory examples = load_examples_from_directory(EXAMPLES_DIR) # Add each example sentence and explanation as a card for example in examples: sentence, explanation = example['sentence'], example['explanation'] note = genanki.Note( model=anki_model, fields=[sentence, explanation]) anki_deck.add_note(note) # Create a package (this will save the deck as an .apkg file) genanki.Package(anki_deck).write_to_file(OUTPUT_FILE) print(f"Anki deck has been created and saved as '{OUTPUT_FILE}'.") This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ [tool.poetry] name = "anki" version = "0.1.0" description = "" authors = ["Milad Khajavi <khajavi@gmail.com>"] readme = "README.md" [tool.poetry.dependencies] python = "^3.11" genanki = "^0.13.1" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"