"""
WSGI config for gitscore project.

"""

import os

from django.core.wsgi import get_wsgi_application

import json
from django.core.exceptions import ImproperlyConfigured
from pathlib import Path

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# JSON-based secrets module
SETTINGS_JSON = str(BASE_DIR) + '/settings.json'

with open(SETTINGS_JSON) as f:
    secrets = json.loads(f.read())


def get_secret(setting, secrets=secrets):
    '''Get the secret variable or return explicit exception'''
    try:
        return secrets[setting]
    except KeyError:
        error_msg = 'Set the {0} environment variable'.format(setting)
        raise ImproperlyConfigured(error_msg)

DJANGO_SETTINGS_MODULE = get_secret('DJANGO_SETTINGS_MODULE')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', DJANGO_SETTINGS_MODULE)

application = get_wsgi_application()