Beispiel #1
0
def create_logger():
    global logger

    if logger is not None:
        return logger

    logger = logging.getLogger(settings('application_name'))
    logger.setLevel(level=1)

    handler_stream = logging.StreamHandler()
    handler_stream.formatter = LogFormatter()
    logger.addHandler(handler_stream)
    logger.propagate = False

    return logger
Beispiel #2
0
    def format(self, record):
        log = {
            "timestamp": time(),
            "_application": settings('application_name'),
            "_environment": self._env,
            "host": self._host,
            "level": self.__get_log_level(record.levelno),
            "_log_type": "application",
            "short_message": record.msg,
        }

        for attr in vars(record):
            if attr[0] == "_":
                log[attr] = getattr(record, attr)

        return dumps(log)
def main():
    commands = available_commands()
    parser = argparse.ArgumentParser(description=settings('application_description'))
    parser.add_argument('--rds',
                        help='Desired action',
                        nargs='+',
                        choices=commands['rds'].keys(),
                        required=False)
    parser.add_argument('--ec2',
                        help='Desired action',
                        nargs='+',
                        choices=commands['ec2'].keys(),
                        required=False)

    args = parser.parse_args()

    if args.rds:
        command = commands['rds'][args.rds[0]]
        command()
    elif args.ec2:
        command = commands['ec2'][args.ec2[0]]
        command()
    else:
        logging.error("args not found")
Beispiel #4
0
print(settings.VALUE)
print(type(settings.VALUE))

print("\nThe debug is:")
print(settings.DEBUG)
print(type(settings.DEBUG))

print("\nThe list is:")
print(settings.ALIST)
print(len(settings.ALIST))
print(type(settings.ALIST))

print("\nThe dict is:")
print(settings.ADICT)
print(settings.ADICT.keys())
print(type(settings.ADICT))

print("\nThe value that may not exist can have a default :")
print(settings.get('FOO', default='bar'))

print("\nThe host for default :")
print(settings.HOSTNAME)

print("\nDotted path lookup value :")
print(settings('ADICT.KEY'))

print(settings.WORKS)

print("\nDotted path set value :")
print(settings.set('ONE.TWO', 'value'))
Beispiel #5
0
    "settings.yml",
    "settings.toml.default",
    "settings.toml.global",
    "settings.tml.default",
    "settings.tml.global",
    "settings.ini",
    "settings.conf",
    "settings.properties",
    "settings.json.default",
    "settings.json.global",
    ".env",
)

for key in keys:
    assert key in settings.A_BIG_DICT.file
    assert key in settings("A_BIG_DICT").file
    assert key in settings("A_BIG_DICT")["file"]
    assert key in settings("A_BIG_DICT").get("file")
    assert key in settings.A_BIG_DICT["file"]
    assert key in settings.A_BIG_DICT.get("file")

print("Big nest",
      settings.A_BIG_DICT.nested_1.nested_2.nested_3.nested_4)  # noqa

assert settings.A_BIG_DICT.nested_1.nested_2.nested_3.nested_4 == {
    "json": True,
    "yaml": True,
    "toml": True,
    "py": True,
}
Beispiel #6
0
print(len(settings.ALIST))
print(type(settings.ALIST))

print("\nThe dict is:")
print(settings.ADICT)
print(settings.ADICT.keys())
print(type(settings.ADICT))

print("\nThe value that may not exist can have a default :")
print(settings.get("FOO", default="bar"))

print("\nThe host for default :")
print(settings.HOSTNAME)

print("\nDotted path lookup value :")
print(settings("ADICT.KEY"))

print(settings.WORKS)

print("\nDotted path set value :")
print(settings.set("ONE.TWO", "value"))

assertions = {
    "WORKS": "full_example",
    "HOSTNAME": "host.com",
    "PORT": 5000,
    "VALUE": 42.1,
    "ALIST": ["item1", "item2", "item3"],
    "ADICT": {
        "key": "value"
    },
Beispiel #7
0
# https://www.programcreek.com/python/example/107718/speech_recognition.AudioFile
# https://stackoverflow.com/questions/52998871/unable-to-resolve-missing-google-api-python-client-module-using-speech-recogniti

import os

from dynaconf import settings
from flask_api import FlaskAPI
import speech_recognition as sr
from flask import request, flash, redirect, render_template

ALLOWED_EXTENSIONS = {'wav'}

app = FlaskAPI(__name__)

app.secret_key = os.urandom(24)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = settings('PATH_AUTH_GOOGLE')

r = sr.Recognizer()


def allowed_file(filename):
    return '.' in filename and \
        filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@app.route('/speech-to-text', methods=['GET', 'POST'], strict_slashes=False)
def upload_file():

    default_options = {'show_all': 'True', 'api_type': 'google_web'}

    if request.method == 'POST':
Beispiel #8
0
def get_config(key=None, default=None, cast=None):
    return getenv(key) or settings(key, default, cast=cast)