From 8a8ac24c73bac52278831490732da93252efe6b9 Mon Sep 17 00:00:00 2001 From: zevav Date: Tue, 12 Feb 2019 19:45:11 -0500 Subject: [PATCH] changed dir structure and modified setup.py to use tatt package --- config.py | 22 --------- exceptions.py | 9 ---- helpers.py | 77 ----------------------------- setup.py | 6 +-- tatt/helpers.py | 5 +- transcribe.py => tatt/transcribe.py | 8 ++- tatt/vendors/amazon.py | 4 +- 7 files changed, 10 insertions(+), 121 deletions(-) delete mode 100644 config.py delete mode 100644 exceptions.py delete mode 100644 helpers.py rename transcribe.py => tatt/transcribe.py (97%) diff --git a/config.py b/config.py deleted file mode 100644 index 5fc8a65..0000000 --- a/config.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -from pathlib import Path -import sqlite3 - - -STT_SERVICES = { - 'amazon': { - 'cost_per_minute': .024, - 'free': '60_minutes_per_month_for_the_first_12_months', - }, - } - - -AWS_BUCKET_NAME_FMTR_MEDIA = 'tatt-media-{}' -AWS_BUCKET_NAME_FMTR_TRANSCRIPT = 'tatt-transcript-{}' -AWS_CREDENTIALS_FILEPATH = ( - os.getenv('AWS_CREDENTIALS_FILEPATH') - or Path.home() / '.aws/credentials' -) -AWS_REGION = 'us-east-1' - -SERVICE_CLASS_NAME = 'transcribe' diff --git a/exceptions.py b/exceptions.py deleted file mode 100644 index 736cdf3..0000000 --- a/exceptions.py +++ /dev/null @@ -1,9 +0,0 @@ - -class ConfigError(Exception): - pass - - -class AlreadyExistsError(Exception): - pass - - diff --git a/helpers.py b/helpers.py deleted file mode 100644 index 932783b..0000000 --- a/helpers.py +++ /dev/null @@ -1,77 +0,0 @@ -import config - -from tatt import vendors - - -def print_all_services(free_only=False, print_=True): - # TODO: make a jinja template for this - all_services_string = ( - '\n\nHere are all the available ' + - f'{"free " if free_only else ""}speech-to-text services:' + - '\n\n' + - '\n'.join(['{}{}{}{}'.format('\t', service_name, '\t\t', - - f'({info["free"].replace("_", " ")})' - if isinstance(info["free"], str) else "" - - ) - - for service_name, info in - config.STT_SERVICES.items()]) - + '\n' - ) - if print_: - print(all_services_string) - return all_services_string - - - -def get_service(service_name): - return getattr(getattr(vendors, service_name), config.SERVICE_CLASS_NAME) - - -def print_transcription_jobs(jobs): - max_job_name_length = max(len(job['name']) - for job_list in jobs.values() - for job in job_list) - max_service_name_length = max(len(provider_name) for provider_name in jobs) - print() - print('Service', - 'Job Name', - (max_job_name_length - len('Job Name')) * ' ', - ' Status') - print('-------', - '--------', - (max_job_name_length - len('Job Name')) * ' ', - ' ------') - - for provider_name, job_list in jobs.items(): - for job in job_list: - num_spaces_between = max_job_name_length - len(job['name']) - print(provider_name, job['name'], ' ' * num_spaces_between, - job['status'], sep=' ') - print() - - -def get_transcription_jobs(service_name=None, name=None, status=None): - all_jobs = {} - for stt_name, data in config.STT_SERVICES.items(): - if service_name is None or service_name == stt_name: - jobs = get_service(stt_name).get_transcription_jobs( - job_name_query=name, - status=status) - if jobs: - all_jobs[stt_name] = jobs - return all_jobs - - -def get_transcription_jobs_dict(): - jobs = get_transcription_jobs() - return { - job['name']: { - 'service_name': service_name, - 'status': job['status'] - } - for service_name, job_list in jobs.items() - for job in job_list - } diff --git a/setup.py b/setup.py index 5d4af60..a790efc 100644 --- a/setup.py +++ b/setup.py @@ -11,10 +11,10 @@ setup( 'boto3', 'requests', ], - dependency_links=['https://github.com/zevaverbach/tatt#egg=package-0.1'], - packages=find_packages(), + # dependency_links=['https://github.com/zevaverbach/tatt#egg=package-0.1'], + packages=['tatt'], entry_points=''' [console_scripts] - transcribe=transcribe:cli + transcribe=tatt.transcribe:cli ''', ) diff --git a/tatt/helpers.py b/tatt/helpers.py index 7236708..f5970bd 100644 --- a/tatt/helpers.py +++ b/tatt/helpers.py @@ -1,6 +1,5 @@ -import config - -import vendors +from tatt import config +from tatt import vendors def print_all_services(free_only=False, print_=True): diff --git a/transcribe.py b/tatt/transcribe.py similarity index 97% rename from transcribe.py rename to tatt/transcribe.py index a7468e6..f1162b4 100644 --- a/transcribe.py +++ b/tatt/transcribe.py @@ -5,9 +5,9 @@ import sys import click -import config -import exceptions -import helpers +from tatt import config +from tatt import exceptions +from tatt import helpers from tatt import vendors @@ -87,5 +87,3 @@ def this(dry_run, media_filepath, service_name): raise click.ClickException(str(e)) print(f'Okay, job {job_num} is being transcribed. Use "get" ' 'command to download it.') - - diff --git a/tatt/vendors/amazon.py b/tatt/vendors/amazon.py index 5a612b5..1dd94cd 100644 --- a/tatt/vendors/amazon.py +++ b/tatt/vendors/amazon.py @@ -6,8 +6,8 @@ import uuid import boto3 -import config -import exceptions +from tatt import config +from tatt import exceptions NAME = 'amazon' BUCKET_NAME_MEDIA = config.AWS_BUCKET_NAME_FMTR_MEDIA.format(NAME)