Exemplo n.º 1
0
def save_a_recording():
    """Given the audio metadata & audio file, resamples it, saves to storage.
    """
    validator = WakeWordValidator()
    formatter = WakeWordFormatter()
    data = request.form
    issues = validator.validate(data)
    if issues:
        try:
            data = validator.fix(data, issues)
        except WakeWordValidatorError as err:
            return str(err), BAD_REQUEST
    formatted_data = formatter.format(data)
    filename = create_filename(formatted_data)

    # Save the audiofile first because if error then we stop here
    # We do not want to save any metadata to the NimbusDatabase
    #   if the audio fails to save.
    save_audiofile(filename, request.files["wav_file"])

    # Let's also save the filename to the database for quick reference
    formatted_data['filename'] = filename

    db = NimbusMySQLAlchemy(config_file=CONFIG_FILE_PATH)
    try:
        db.save_audio_sample_meta_data(formatted_data)
    except BadDictionaryKeyError as e:
        return str(e), BAD_REQUEST
    except BadDictionaryValueError as e:
        return str(e), BAD_REQUEST
    except NimbusDatabaseError as e:
        return str(e), BAD_REQUEST
    except Exception as e:
        # TODO: consider security tradeoff of displaying internal server errors
        #       versus development time (being able to see errors quickly)
        # HINT: security always wins
        raise e

    return filename
Exemplo n.º 2
0
def save_calendars():
    """
    Persists list of calendars
    """
    data = request.get_json()
    db = NimbusMySQLAlchemy(config_file=CONFIG_FILE_PATH)
    for calendar in data['calendars']:
        try:
            db.save_calendar(calendar)
        except BadDictionaryKeyError as e:
            return str(e), BAD_REQUEST
        except BadDictionaryValueError as e:
            return str(e), BAD_REQUEST
        except NimbusDatabaseError as e:
            return str(e), BAD_REQUEST
        except Exception as e:
            # TODO: consider security tradeoff of displaying internal server errors
            #       versus development time (being able to see errors quickly)
            # HINT: security always wins
            raise e

    return "SUCCESS"
Exemplo n.º 3
0
Arquivo: QA.py Projeto: snekiam/api
Extracted_Vars = Dict[str, Any]
DB_Data = Dict[str, Any]
DB_Query = Callable[[Extracted_Vars], DB_Data]
Answer_Formatter = Callable[[Extracted_Vars, DB_Data], str]

tag_lookup = {
    'PROF': Professors,
    'CLUB': Clubs,
    'COURSE': Courses,
    'SECRET_HIDEOUT': Locations,
    'SECTION': Sections
}

# TODO: Initialize this somewhere else. Currently here because of _get_property()
# Move into the Nimbus class below if possible.
db = NimbusMySQLAlchemy()


class QA:
    """
    A class for wrapping functions used to answer a question.
    """
    def __init__(self, q_format, db_query, format_answer):
        """
        Args:
            q_format (str): Question format string
            db (NimbusDatabase): Object used to access remote database
            db_query (DB_Query): Function used to get data from database. Takes
                a dict of extracted variables and returns a dict of variables
                from the database.
            format_function (Answer_Formatter): Function used to format answer
Exemplo n.º 4
0
#!/usr/bin/env python3
from database_wrapper import NimbusMySQLAlchemy

db = NimbusMySQLAlchemy(config_file='config.json')
db._create_all_tables()