Esempio n. 1
0
    elif name == "n2a-basic":
        return 2020
    # https://stackoverflow.com/questions/16008670/how-to-hash-a-string-into-8-digits
    return abs(
        int(hashlib.sha1(name.encode("utf-8")).hexdigest(), 16) % (10**8))


if __name__ == "__main__":
    if len(sys.argv) < 3:
        raise IOError(
            'missing payload arguments(data file, deck style, template dir)')
    data_file = sys.argv[1]
    deck_style = sys.argv[2]
    template_dir = sys.argv[3]

    CSS = _read_template(template_dir, deck_style, "", "")
    CLOZE_STYLE = _read_template(template_dir, "cloze_style.css", "", "")

    with open(data_file, "r", encoding="utf-8") as json_file:
        data = json.load(json_file)
        media_files = []
        decks = []

        # Model / Template stuff
        mt = data[0]["settings"]

        # Retreive template names for user or get the default ones
        cloze_model_name = mt.get('clozeModelName', "n2a-cloze")
        basic_model_name = mt.get('basicModelName', "n2a-basic")
        input_model_name = mt.get('inputModelName', "n2a-input")
Esempio n. 2
0
import os
import json
from genanki import Model
from fs_util import _read_template

DEFAULT_BASIC = json.loads(
    _read_template(
        os.path.dirname(__file__) + "/../../templates/", "n2a-basic.json", "",
        ""))


def basic_model(id, name, css, qfmt, afmt):
    if qfmt is None:
        qfmt = DEFAULT_BASIC.get('front')
    if afmt is None:
        afmt = DEFAULT_BASIC.get('back')

    return Model(
        id,
        name,
        fields=DEFAULT_BASIC.get("fields"),
        templates=[{
            "name": name,
            "qfmt": qfmt,
            "afmt": afmt,
        }],
        css=css,
    )
Esempio n. 3
0
from models.input import input_model
from models.cloze import cloze_model
from models.basic import basic_model

from fs_util import _read_template, _build_deck_description, _wr_apkg

if __name__ == "__main__":
    if len(sys.argv) < 3:
        raise IOError(
            'missing payload arguments(data file, deck style, template dir)')
    data_file = sys.argv[1]
    deck_style = sys.argv[2]
    template_dir = sys.argv[3]

    CSS = _read_template(template_dir, deck_style, "", "")
    CLOZE_STYLE = _read_template(template_dir, "cloze_style.css", "", "")

    with open(data_file, "r", encoding="utf-8") as json_file:
        data = json.load(json_file)
        media_files = []
        decks = []

        # Model / Template stuff
        mt = data[0]
        cloze_model_name = mt.get('cloze_model_name', "n2a") + "-cloze"
        basic_model_name = mt.get('basic_model_name', "n2a") + "-basic"
        input_model_name = mt.get('input_model_name', "n2a") + "-input"
        input_model_id = mt.get('input_model_id', 6394002335189144856)
        cloze_model_id = mt.get('cloze_model_id', 998877661)
        basic_model_id = mt.get('basic_model_id', 2020)