fixed is_path helper, added pretty printing option and turned it off by default, for piping
This commit is contained in:
2
setup.py
2
setup.py
@@ -6,7 +6,7 @@ with open('README_PYPI.md') as file:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="tpro",
|
name="tpro",
|
||||||
version="0.06",
|
version="0.08",
|
||||||
url='https://github.com/zevaverbach/tpro',
|
url='https://github.com/zevaverbach/tpro',
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'Click',
|
'Click',
|
||||||
|
|||||||
@@ -40,4 +40,7 @@ def get_punc_after(word):
|
|||||||
|
|
||||||
|
|
||||||
def is_path(string):
|
def is_path(string):
|
||||||
return Path(string).exists()
|
try:
|
||||||
|
return Path(string).exists()
|
||||||
|
except OSError:
|
||||||
|
return False
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
def universal_transcript(self):
|
def universal_transcript(self, pretty=False):
|
||||||
return json.dumps(self.converted_words, indent=4)
|
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([{
|
return json.dumps([{
|
||||||
'start': word['start'],
|
'start': word['start'],
|
||||||
'stop': word['end'],
|
'stop': word['end'],
|
||||||
'text': word['word'].title() if word['always_capitalized'] else word['word']}
|
'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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,13 @@ output_choices = [k for k, v in
|
|||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('-s', '--save', type=str, help='save to JSON file')
|
@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('json_path_or_data', type=str)
|
||||||
@click.argument('input_format', type=click.Choice(services.keys()))
|
@click.argument('input_format', type=click.Choice(services.keys()))
|
||||||
@click.argument('output_format', type=click.Choice(output_choices))
|
@click.argument('output_format', type=click.Choice(output_choices))
|
||||||
def cli(save,
|
def cli(save,
|
||||||
|
pretty,
|
||||||
json_path_or_data,
|
json_path_or_data,
|
||||||
input_format,
|
input_format,
|
||||||
output_format):
|
output_format):
|
||||||
@@ -34,4 +37,4 @@ def cli(save,
|
|||||||
click.echo(f'{path} saved.')
|
click.echo(f'{path} saved.')
|
||||||
else:
|
else:
|
||||||
output_formatter = getattr(converter, output_format)
|
output_formatter = getattr(converter, output_format)
|
||||||
click.echo(output_formatter())
|
click.echo(output_formatter(pretty))
|
||||||
|
|||||||
Reference in New Issue
Block a user