forked from nicholsons/comp0034-wk4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
50 lines (37 loc) · 1.27 KB
/
__init__.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
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase
from flask_marshmallow import Marshmallow
class Base(DeclarativeBase):
pass
db = SQLAlchemy(model_class=Base)
ma = Marshmallow()
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='l-tirPCf1S44mWAGoWqWlA',
SQLALCHEMY_DATABASE_URI="sqlite:///" + os.path.join(app.instance_path, 'complex.db'),
SQLALCHEMY_ECHO=True,
)
if test_config is None:
app.config.from_pyfile('config.py', silent=True)
else:
app.config.from_mapping(test_config)
try:
os.makedirs(app.instance_path)
except OSError:
pass
db.init_app(app)
ma.init_app(app)
with app.app_context():
# Create the database and tables if they don't already exist
from complexdb.models import Prediction, Bloom, Temperature
db.create_all()
# Add the data to the database if not already added
# Pass the sqlalchemy db to the function
from complexdb.db_utils import add_data
add_data(db)
# Register the routes with the app in the context
from complexdb import routes
return app