Start ankimaker.
This commit is contained in:
commit
7339b27ec4
9
ankimaker/__main__.py
Normal file
9
ankimaker/__main__.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from ankimaker.commands import cli
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cli(prog_name='ankimaker')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
7
ankimaker/commands/__init__.py
Normal file
7
ankimaker/commands/__init__.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import click
|
||||||
|
|
||||||
|
@click.group("cli")
|
||||||
|
def cli():
|
||||||
|
pass
|
||||||
|
|
||||||
|
from ankimaker.commands.from_csv import generate_anki
|
38
ankimaker/commands/from_csv.py
Normal file
38
ankimaker/commands/from_csv.py
Normal file
@ -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
|
0
ankimaker/commands/from_epub.py
Normal file
0
ankimaker/commands/from_epub.py
Normal file
1
ankimaker/tasks/__init__.py
Normal file
1
ankimaker/tasks/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .basic_csv_to_anki import basic_pandas_to_anki
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
click
|
||||||
|
genanki
|
||||||
|
pandas
|
Loading…
x
Reference in New Issue
Block a user