<commit_before>import os
import subprocess
from flask import Flask
from flask.ext.mongoengine import MongoEngine

app = Flask(__name__)
config_path = os.getenv('CONFIG_PATH', 'mass_flask_config.config_development.DevelopmentConfig')
app.config.from_object(config_path)
db = MongoEngine(app)
app.version = subprocess.check_output(['git', 'describe'], cwd=os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
<commit_msg>Adding secret key generation, related to MASS-116.<commit_after>import os
import subprocess
from flask import Flask
from flask.ext.mongoengine import MongoEngine

# Initialize app
app = Flask(__name__)

# Generate or load secret key
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_FILE = os.path.join(BASE_DIR, 'secret.txt')
try:
    app.secret_key = open(SECRET_FILE).read().strip()
except IOError:
    try:
        import random
        app.secret_key = ''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
        secret = open(SECRET_FILE, 'w')
        secret.write(app.secret_key)
        secret.close()
    except IOError:
        Exception('Please create a %s file with random characters \
        to generate your secret key!' % SECRET_FILE)

# Load config
config_path = os.getenv('CONFIG_PATH', 'mass_flask_config.config_development.DevelopmentConfig')
app.config.from_object(config_path)

# Init db
db = MongoEngine(app)

# Load app version from git
app.version = subprocess.check_output(['git', 'describe'], cwd=os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

{'fraction_non_alphanumeric': 0.13018867924528302, 'fraction_numerical': 0.009433962264150943, 'mean_word_length': 5.072519083969466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '779531', 'n_tokens_mistral': 550, 'n_tokens_neox': 516, 'n_words': 110}