2019-11-29 14:04:32 +00:00
|
|
|
from os import environ, urandom
|
|
|
|
|
|
|
|
from flask import Flask
|
2019-12-13 17:23:06 +00:00
|
|
|
from flask.cli import load_dotenv
|
2019-11-29 14:04:32 +00:00
|
|
|
from flask_httpauth import HTTPBasicAuth
|
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2020-04-27 12:02:38 +00:00
|
|
|
from werkzeug.security import generate_password_hash
|
2019-11-29 14:04:32 +00:00
|
|
|
|
2019-12-15 11:42:46 +00:00
|
|
|
load_dotenv()
|
2019-11-29 14:04:32 +00:00
|
|
|
|
2019-12-07 09:17:29 +00:00
|
|
|
IS_DEBUG = environ.get('FLASK_ENV', 'production') == 'development'
|
|
|
|
ADMIN_USERNAME = environ.get('ADMIN_USERNAME', 'admin')
|
2020-04-27 12:02:38 +00:00
|
|
|
ADMIN_PASSWORD = generate_password_hash(environ.get('ADMIN_PASSWORD', 'secret'))
|
2019-12-07 09:17:29 +00:00
|
|
|
APP_PORT = environ.get('FLASK_PORT', 5000)
|
2019-12-23 09:34:38 +00:00
|
|
|
CACHE_TIMEOUT = environ.get('CACHE_TIMEOUT', 60 * 60)
|
2020-02-21 16:11:07 +00:00
|
|
|
BLACKLIST_WORDS = environ.get('BLACKLIST_WORDS', '').split(',')
|
2020-04-09 12:02:05 +00:00
|
|
|
MYSQL_ENABLED = False
|
2019-12-07 09:17:29 +00:00
|
|
|
|
2019-11-29 14:04:32 +00:00
|
|
|
app = Flask(__name__)
|
2019-12-26 22:12:56 +00:00
|
|
|
app.name = 'PyNyaaTa'
|
2019-12-07 09:17:29 +00:00
|
|
|
app.secret_key = urandom(24).hex()
|
2020-01-05 11:24:23 +00:00
|
|
|
app.url_map.strict_slashes = False
|
2019-11-29 14:04:32 +00:00
|
|
|
auth = HTTPBasicAuth()
|
2020-04-09 12:02:05 +00:00
|
|
|
|
|
|
|
db_host = environ.get('MYSQL_SERVER')
|
|
|
|
if db_host:
|
|
|
|
MYSQL_ENABLED = True
|
|
|
|
db_user = environ.get('MYSQL_USER')
|
|
|
|
db_password = environ.get('MYSQL_PASSWORD')
|
|
|
|
db_name = environ.get('MYSQL_DATABASE')
|
|
|
|
if not db_user or not db_password or not db_name:
|
|
|
|
print('Missing connection environment variables')
|
|
|
|
exit()
|
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://%s:%s@%s/%s?charset=utf8mb4' % (
|
|
|
|
db_user, db_password, db_host, db_name
|
|
|
|
)
|
|
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
|
|
|
app.config['SQLALCHEMY_ECHO'] = IS_DEBUG
|
2020-04-11 12:34:34 +00:00
|
|
|
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {
|
|
|
|
'pool_recycle': 200
|
|
|
|
}
|
2020-04-09 12:02:05 +00:00
|
|
|
db = SQLAlchemy(app)
|