45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_wtf import CSRFProtect
|
|
from models import db, Company
|
|
import os
|
|
from routes import register_routes
|
|
|
|
app = Flask(__name__)
|
|
|
|
# Construct the full path for the SQLite database
|
|
database_path = os.path.join(app.root_path, 'instance', 'daily_overview.sqlite')
|
|
|
|
# Ensure the instance directory exists
|
|
instance_path = os.path.join(app.root_path, 'instance')
|
|
if not os.path.exists(instance_path):
|
|
os.makedirs(instance_path)
|
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{database_path}'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
app.config['SECRET_KEY'] = 'your_secret_key'
|
|
|
|
db.init_app(app)
|
|
csrf = CSRFProtect(app)
|
|
|
|
print(f"Instance path: {instance_path}")
|
|
print(f"Database path: {database_path}")
|
|
print(f"Database URI: {app.config['SQLALCHEMY_DATABASE_URI']}")
|
|
|
|
with app.app_context():
|
|
try:
|
|
db.create_all()
|
|
if Company.query.count() == 0:
|
|
company1 = Company(name="Hartford Funding")
|
|
company2 = Company(name="Alpha Tech Lending")
|
|
db.session.add(company1)
|
|
db.session.add(company2)
|
|
db.session.commit()
|
|
except Exception as e:
|
|
print(f"Error creating database: {e}")
|
|
|
|
register_routes(app)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', debug=True, port=5005)
|