-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobal_var.py
More file actions
37 lines (30 loc) · 930 Bytes
/
global_var.py
File metadata and controls
37 lines (30 loc) · 930 Bytes
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
# coding=utf-8
import time
from flask import Flask, jsonify
from flask_httpauth import HTTPBasicAuth
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# 设置密钥
app.config['SECRET_KEY'] = 'the quick brown fox jumps over the lazy dog'
# 数据库的配置
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///user.db'
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# 数据库初始化
db = SQLAlchemy(app)
# 验证的初始化
auth = HTTPBasicAuth()
expire_time = 24 * 60 * 60
user_db_name = 'user.db'
def generate_resp(code, data=None, message=None):
res = {'server_time': int(round(time.time() * 1000))}
if code:
res['result_code'] = code
if message:
res['message'] = message
if data:
res['data'] = data
return jsonify(res)
def run():
# 如果这个数据库不存在就创建
app.run(debug=True)