51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from flask import Flask
|
|
|
|
import os
|
|
import logging
|
|
import secrets
|
|
from . import local_db
|
|
|
|
from .api import shipcalls
|
|
from .api import verify
|
|
from .api import participant
|
|
from .api import times
|
|
from .api import notifications
|
|
from .api import berths
|
|
from .api import ships
|
|
|
|
sessions = dict()
|
|
|
|
def create_app(test_config=None):
|
|
|
|
app = Flask(__name__, instance_relative_config=True)
|
|
app.config.from_mapping(
|
|
SECRET_KEY='dev'
|
|
)
|
|
if test_config is None:
|
|
app.config.from_pyfile('config.py', silent=True)
|
|
else:
|
|
app.config.from_mapping(test_config)
|
|
|
|
try:
|
|
print(f'Instance path = {app.instance_path}')
|
|
os.makedirs(app.instance_path)
|
|
except OSError:
|
|
pass
|
|
|
|
# Add blueprints
|
|
app.register_blueprint(shipcalls.bp)
|
|
app.register_blueprint(verify.bp)
|
|
app.register_blueprint(participant.bp)
|
|
app.register_blueprint(times.bp)
|
|
app.register_blueprint(notifications.bp)
|
|
app.register_blueprint(berths.bp)
|
|
app.register_blueprint(ships.bp)
|
|
|
|
logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s')
|
|
local_db.initPool()
|
|
logging.info('App started')
|
|
|
|
return app
|
|
|
|
def create_api_key():
|
|
return secrets.token_urlsafe(16) |