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
|
|
|
|
|
|
|
|
# init DB and migration
|
2019-12-15 11:42:46 +00:00
|
|
|
load_dotenv()
|
2019-11-29 14:04:32 +00:00
|
|
|
db_user = environ.get('MYSQL_USER')
|
|
|
|
db_password = environ.get('MYSQL_PASSWORD')
|
|
|
|
db_name = environ.get('MYSQL_DATABASE')
|
2019-11-30 22:42:35 +00:00
|
|
|
db_host = environ.get('MYSQL_SERVER')
|
2019-11-29 14:04:32 +00:00
|
|
|
if not db_host or not db_user or not db_password or not db_name:
|
|
|
|
print('Missing connection environment variables')
|
|
|
|
exit()
|
|
|
|
|
2019-12-07 09:17:29 +00:00
|
|
|
# load app constants
|
|
|
|
IS_DEBUG = environ.get('FLASK_ENV', 'production') == 'development'
|
|
|
|
ADMIN_USERNAME = environ.get('ADMIN_USERNAME', 'admin')
|
|
|
|
ADMIN_PASSWORD = environ.get('ADMIN_PASSWORD', 'secret')
|
|
|
|
APP_PORT = environ.get('FLASK_PORT', 5000)
|
2019-12-23 09:34:38 +00:00
|
|
|
CACHE_TIMEOUT = environ.get('CACHE_TIMEOUT', 60 * 60)
|
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()
|
2019-12-15 11:42:46 +00:00
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://%s:%s@%s/%s?charset=utf8mb4' % (
|
|
|
|
db_user, db_password, db_host, db_name
|
|
|
|
)
|
2019-11-29 14:04:32 +00:00
|
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
2019-12-27 13:18:59 +00:00
|
|
|
app.config['SQLALCHEMY_POOL_RECYCLE'] = 200
|
2019-12-07 09:17:29 +00:00
|
|
|
app.config['SQLALCHEMY_ECHO'] = IS_DEBUG
|
2019-11-29 14:04:32 +00:00
|
|
|
auth = HTTPBasicAuth()
|
|
|
|
db = SQLAlchemy(app)
|