Example #1
0
def _wr_apkg(notes):
    """Write cloze cards to an Anki apkg file"""
    deckname = 'mtherieau'
    deck = Deck(deck_id=0, name=deckname)
    for note in notes:
        deck.add_note(note)
    fout_anki = '{NAME}.apkg'.format(NAME=deckname)
    Package(deck).write_to_file(fout_anki)
    print('  {N} Notes WROTE: {APKG}'.format(N=len(notes), APKG=fout_anki))
Example #2
0
def _wr_apkg(notes, deck_id, deck_name, media_files):
    """Write cloze cards to an Anki apkg file"""
    deck = Deck(deck_id=deck_id, name=deck_name, description=DESC)
    for note in notes:
        deck.add_note(note)

    fout_anki = '{NAME}.apkg'.format(NAME=deck_id)
    pkg = Package(deck)
    pkg.media_files = media_files
    pkg.write_to_file(fout_anki)
    sys.stdout.write(os.getcwd() + '/' + fout_anki)
Example #3
0
def render_anki():
    problems = Problem.select().order_by(Problem.display_id)

    anki_deck = Deck(deck_id=random_id(), name="LeetCode")

    for problem in problems:
        note = make_note(problem)
        anki_deck.add_note(note)

    path = conf.get("Anki", "output")
    Package(anki_deck).write_to_file(path)
Example #4
0
def _wr_apkg(payload, media_files):
    firstId = ""
    decks = []

    for p in payload:
        deck = Deck(deck_id=p["id"], name=p["name"], description=p["desc"])
        if not firstId:
            firstId = p["id"]
        for note in p["notes"]:
            deck.add_note(note)
        decks.append(deck)

    pkg = Package(decks)
    pkg.media_files = media_files
    fout_anki = "{NAME}.apkg".format(NAME=firstId)

    pkg.write_to_file(fout_anki)
    sys.stdout.write(os.getcwd() + "/" + fout_anki)
def create_anki_package(pkg):

    pkg_dir = PurePath(pkg.filename).parent
    Path(pkg_dir).mkdir(parents=True, exist_ok=True)

    deck = Deck(pkg.deck.id, pkg.deck.name)
    for n in pkg.deck.notes:
        model = get_anki_model(n.model)
        template = get_data_template(n.template)
        for d in n.data:
            items = get_anki_items(d)
            for item in items:
                note = get_anki_note(item=item, model=model, template=template)
                # print(note.guid, note.tags)
                deck.add_note(note)

    package = Package(deck)
    package.write_to_file(pkg.filename)

    return pkg.filename
def generate(deck_name, audio_dir):
    audio_files = listdir(audio_dir)
    model = hanzi_english_model(deck_name)
    deck = Deck(
        2059400110,
        'Chinese Deck')
    deck = add_notes(audio_files=audio_files, model=model, deck=deck)
    package = Package(deck)
    full_paths = [join(audio_dir, filename)
                  for filename in audio_files]
    write_package(package=package, audio_files=full_paths)
Example #7
0
    try:
        prac_pts = driver.find_elements_by_class_name(
            'prac-pts')[1].text.replace('\n', ' <br/>').replace(
                'Practice points:', ' ')
        field += "<br /><b> Practical points </b> <br /> {{c5::" + prac_pts + "}}"
    except:
        print("practical points not found")

    field += "'"
    fields = [field, ' ']
    # # Question: NOTE TWO: [...]              2nd deletion     3rd deletion
    # # Answer:   NOTE TWO: **1st deletion**   2nd deletion     3rd deletion
    # #
    # # Question: NOTE TWO: 1st deletion       [...]            3rd deletion
    # # Answer:   NOTE TWO: 1st deletion     **2nd deletion**   3rd deletion
    # #
    # # Question: NOTE TWO: 1st deletion       2nd deletion     [...]
    # # Answer:   NOTE TWO: 1st deletion       2nd deletion   **3rd deletion**
    # fields = ['NOTE TWO: {{c1::1st deletion}} {{c2::2nd deletion}} {{c3::3rd deletion}}', '']
    my_cloze_note = Note(model=MY_CLOZE_MODEL, fields=fields)
    notes.append(my_cloze_note)

deckname = 'AMH_drugs'
deck = Deck(deck_id=0, name=deckname)
for note in notes:
    deck.add_note(note)
fout_anki = '{NAME}.apkg'.format(NAME=deckname)
Package(deck).write_to_file(fout_anki)
print('{N} Notes WROTE: {APKG}'.format(N=len(notes), APKG=fout_anki))
Example #8
0
def create_anki_deck(text, deckname=None, filename=None):
    from genanki import Model, Note, Deck, Package

    # This is mostly hobbled together from the tests for genanki
    CSS = """.card {
    font-family: arial;
    font-size: 20px;
    text-align: center;
    color: black;
    background-color: white;
    }
    .cloze {
    font-weight: bold;
    color: blue;
    }
    .nightMode .cloze {
    color: lightblue;
    }
    """

    MY_CLOZE_MODEL = Model(
        998877661,
        "Nlaco Cloze Model",
        fields=[{"name": "Text"}, {"name": "Extra"},],
        templates=[
            {
                "name": "Nlaco Cloze Card",
                "qfmt": "{{cloze:Text}}",
                "afmt": "{{cloze:Text}}<br>{{Extra}}",
            },
        ],
        css=CSS,
        model_type=Model.CLOZE,
    )

    name_uuid = uuid4()

    for overlap in range(1, 4):

        notes = [
            Note(model=MY_CLOZE_MODEL, fields=(p, ""))
            for p in get_card_contents(text, phrases_per_cloze=overlap)
        ]
        for n in notes:
            assert (
                n.cards
            ), f"No cards in note {n}, this will cause your Anki DB to break!"

        if deckname is None:
            _deckname = f"nlaco-overlap-{overlap}--" + str(name_uuid)
        else:
            raise NotImplementedError("Custom decknames are not supported yet :(")

        # % 500000 to make sure the int can fit into an SQL database. TODO see
        # whether this is random enough to make sure there are no collisions.
        deck = Deck(deck_id=name_uuid.int % 500000, name=_deckname)
        for note in notes:
            deck.add_note(note)

        if filename is None:
            Package(deck).write_to_file(f"{_deckname}.apkg")
        else:
            raise NotImplementedError("Custom filenames are not supported yet :(")