fixed is_path helper, added pretty printing option and turned it off by default, for piping

This commit is contained in:
2019-02-20 13:04:26 -05:00
parent 667d2ccd05
commit 6333f55c87
4 changed files with 13 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ with open('README_PYPI.md') as file:
setup(
name="tpro",
version="0.06",
version="0.08",
url='https://github.com/zevaverbach/tpro',
install_requires=[
'Click',

View File

@@ -40,4 +40,7 @@ def get_punc_after(word):
def is_path(string):
return Path(string).exists()
try:
return Path(string).exists()
except OSError:
return False

View File

@@ -1,14 +1,14 @@
import json
def universal_transcript(self):
return json.dumps(self.converted_words, indent=4)
def universal_transcript(self, pretty=False):
return json.dumps(self.converted_words, indent=4 if pretty else None)
def viral_overlay(self):
def viral_overlay(self, pretty=False):
return json.dumps([{
'start': word['start'],
'stop': word['end'],
'text': word['word'].title() if word['always_capitalized'] else word['word']}
for word in self.converted_words], indent=4
for word in self.converted_words], indent=4 if pretty else None
)

View File

@@ -12,10 +12,13 @@ output_choices = [k for k, v in
@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):
@@ -34,4 +37,4 @@ def cli(save,
click.echo(f'{path} saved.')
else:
output_formatter = getattr(converter, output_format)
click.echo(output_formatter())
click.echo(output_formatter(pretty))