# -*-coding:utf-8 -*-  

import time
from datetime import datetime, timedelta
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

# 调用Flask App和 SQLAlchemy 组件，创建与数据库的连接
app = Flask(__name__)

database = 'mysql+pymysql://root:tomcat@127.0.0.1:3306/acs'
app.config['SQLALCHEMY_DATABASE_URI'] = database
app.config['SECRET_KEY'] = 'the quick brown fox jumps over the lazy dog'
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(days=10)

# Configure application to store JWTs in cookies
# app.config['JWT_TOKEN_LOCATION'] = ['cookies']

# Only allow JWT cookies to be sent over https. In production, this
# should likely be True
# app.config['JWT_COOKIE_SECURE'] = True
# app.config['JWT_COOKIE_SECURE'] = False
# app.config['JWT_ACCESS_COOKIE_PATH'] = '/'
# app.config['JWT_REFRESH_COOKIE_PATH'] = '/api/'

# Enable csrf double submit protection. See this for a thorough
# explination: http://www.redotheweb.com/2015/11/09/api-security.html
# app.config['JWT_COOKIE_CSRF_PROTECT'] = True

# app.config['JWT_CSRF_IN_COOKIES'] = False

db = SQLAlchemy(app)

# app.run(debug=True)

date_now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))

# 国际时间
# date_time = datetime.utcnow()

# 本地时间
date_time = datetime.now()


# 根据定义的表结构一键构建实体表
def init_db():
    db.create_all()


# 删除数据库表  
def drop_db():
    db.drop_all()


# sqlalchemy.orm.exc.UnmappedInstanceError 异常
# : Class '__builtin__.instance' is not mapped
# 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead 。。。改为True
