-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathautoapp.py
55 lines (43 loc) · 1.69 KB
/
autoapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from dotenv import load_dotenv
import os
load_dotenv(os.environ['DONATE_DOTENV'])
from donate.app import create_app
from donate.database import db
from donate.log_utils import start_timer, log_request
from donate.models import DonateConfiguration
from donate.settings import DevConfig, ProdConfig, TestConfig
from flask.helpers import get_debug_flag
import logging
from logging.handlers import TimedRotatingFileHandler
from sqlalchemy.orm.exc import NoResultFound
if os.environ['FLASK_ENV'] == 'DEVELOPMENT':
CONFIG = DevConfig
elif os.environ['FLASK_ENV'] == 'PRODUCTION':
CONFIG = ProdConfig
elif os.environ['FLASK_ENV'] == 'TESTING':
CONFIG = TestConfig
else:
raise Exception("FLASK_ENV not recognized")
handler = TimedRotatingFileHandler(filename=CONFIG.LOG_FILE,
when="W6", interval=1,
backupCount=52, encoding=None,
delay=False, utc=True, atTime=None)
formatter = logging.Formatter(CONFIG.LOG_FORMAT)
handler.setLevel(CONFIG.LOG_LEVEL)
handler.setFormatter(formatter)
# logging.basicConfig(filename=CONFIG.LOG_FILE,
# format=CONFIG.LOG_FORMAT,
# level=CONFIG.LOG_LEVEL)
if CONFIG.SQLALCHEMY_DATABASE_URI is None:
raise Exception("DATABASE_URI no set")
app = create_app(CONFIG)
# with app.app_context():
# try:
# db.session.query(DonateConfiguration).filter_by(key="INIT").one()
# except NoResultFound:
# raise ValueError("Donate is not initialized")
app.before_request(start_timer)
app.after_request(log_request)
app.logger.addHandler(handler)
app.logger.info("App initialized")
app.secret_key = os.environ['DONATE_SECRET']