updated tests to current format of converters, updated static/not-static decorators on base class to match its children, added GoogleConverter, moved one or two methods to the base class because they all work the same.

This commit is contained in:
2019-03-07 02:30:48 -05:00
parent 6333f55c87
commit d30ecad583
16 changed files with 346 additions and 46 deletions

View File

@@ -0,0 +1,40 @@
import json
import click
from .converters import services
from . import outputs
from . import helpers
output_choices = [k for k, v in
outputs.__dict__.items()
if callable(v)]
@click.command()
@click.option('-s', '--save', type=str, help='save to JSON file')
@click.option('-p', '--pretty', is_flag=True,
help='pretty print the transcript, breaks pipeability')
@click.argument('json_path_or_data', type=str)
@click.argument('input_format', type=click.Choice(services.keys()))
@click.argument('output_format', type=click.Choice(output_choices))
def cli(save,
pretty,
json_path_or_data,
input_format,
output_format):
if not helpers.is_path(json_path_or_data):
json_data = json.loads(json_path_or_data)
else:
with open(json_path_or_data) as fin:
json_data = json.load(fin)
service = services[input_format]
converter = service(json_data)
converter.convert()
if save:
path = save
converter.save(path, output_format)
click.echo(f'{path} saved.')
else:
output_formatter = getattr(converter, output_format)
click.echo(output_formatter(pretty))