commit f76f25eeb7d8fa9863cdb88c261c561608c86af0 Author: gabriel becker Date: Tue Nov 15 17:38:56 2022 +1100 Start ankimaker. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6fcafc5 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Ankimaker + +WIP + +A CLI app to generate anki decks. + +From csv file, with configurable parameters, filters and media. + +From epub, finding difficult* words in the book and getting their translations. + +*I still don't know what 'difficult' will mean. Probably difficult words will be less frequent words that are more frequent in the text than in some corpus, cut above a grade threshold. The grades will map percentiles of frequency. + +| Language Level | Number of Base Words Needed | +| ----- | ------ | +| A1 | 500| +| A2 | 1000| +| B1 | 2000| +| B2 | 4000| +| C1 | 8000| +| C2 | 16000| + + +This project is only possible because of the awesome work of genanki team. \ No newline at end of file diff --git a/ankimaker/__main__.py b/ankimaker/__main__.py new file mode 100644 index 0000000..c50f7e5 --- /dev/null +++ b/ankimaker/__main__.py @@ -0,0 +1,9 @@ +from ankimaker.commands import cli + + +def main(): + cli(prog_name='ankimaker') + + +if __name__ == '__main__': + main() diff --git a/ankimaker/commands/__init__.py b/ankimaker/commands/__init__.py new file mode 100644 index 0000000..10cefc4 --- /dev/null +++ b/ankimaker/commands/__init__.py @@ -0,0 +1,7 @@ +import click + +@click.group("cli") +def cli(): + pass + +from ankimaker.commands.from_csv import generate_anki diff --git a/ankimaker/commands/from_csv.py b/ankimaker/commands/from_csv.py new file mode 100644 index 0000000..22b3f9c --- /dev/null +++ b/ankimaker/commands/from_csv.py @@ -0,0 +1,38 @@ +import click +import re +from ankimaker.commands import cli +from ankimaker.tasks import basic_pandas_to_anki + + +@cli.command('csv') +@click.option('-i', '--input', 'input_file', type=click.Path(exists=True)) +@click.option('-o', '--output', 'output_file', type=click.Path(exists=False)) +@click.option('-c', '--conf', 'config_file', default=None, type=click.STRING) +@click.option('-n', '--name', 'name', default=None, type=click.STRING) +def generate_anki( + input_file, + output_file, + name, + config_file, +): + output_file = parse_output(output_file) + if name is None: + name = get_name_from_output(output_file) + basic_pandas_to_anki(input_file, output_file, name) + + +def parse_output(filename): + filetype = filename.split('.')[-1] if len(filename.split('.')) > 0 else None + if filetype is None: + return filename + '.apkg' + elif filetype != 'apkg': + filename.replace(filetype, 'apkg') + return filename+filetype + else: + return filename + + +def get_name_from_output(filename): + updated_file = filename.split('/')[-1] if len(filename.split('/')) > 0 else filename + updated_file = re.sub(r'(.apkg)', '', updated_file) + return updated_file diff --git a/ankimaker/commands/from_epub.py b/ankimaker/commands/from_epub.py new file mode 100644 index 0000000..e69de29 diff --git a/ankimaker/tasks/__init__.py b/ankimaker/tasks/__init__.py new file mode 100644 index 0000000..026693a --- /dev/null +++ b/ankimaker/tasks/__init__.py @@ -0,0 +1 @@ +from .basic_csv_to_anki import basic_pandas_to_anki diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a7792c2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +click +genanki +pandas \ No newline at end of file