You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
from flask import Flask, jsonify, request
|
|
from datetime import datetime
|
|
from flask_cors import CORS
|
|
import threading
|
|
import json
|
|
import time
|
|
|
|
#region 全局
|
|
|
|
app = Flask(__name__)
|
|
CORS(app)
|
|
port = 15002
|
|
server_cfg = None
|
|
data_dict = dict()
|
|
|
|
#endregion
|
|
|
|
#region 接口
|
|
|
|
# 测试用
|
|
@app.route('/api')
|
|
def hello():
|
|
return 'hi. —— CheckGPUsWeb'
|
|
|
|
@app.route('/api/get_data', methods=['GET'])
|
|
def get_data():
|
|
return jsonify(data_dict)
|
|
|
|
@app.route('/api/update_data', methods=['POST'])
|
|
def receive_data():
|
|
data = request.json
|
|
if (data['title'] in server_cfg['server_list']):
|
|
data_dict['server_dict'][data['title']] = data
|
|
return jsonify({"status": "success"})
|
|
|
|
#endregion
|
|
|
|
def init():
|
|
data_dict['server_dict'] = dict()
|
|
for server_name in server_cfg['server_list']:
|
|
data_dict['server_dict'][server_name] = None
|
|
|
|
def main():
|
|
# 加载配置文件
|
|
cfg_path = "server_config.json"
|
|
global server_cfg
|
|
with open(cfg_path, 'r') as f:
|
|
server_cfg = json.load(f)
|
|
|
|
# flask
|
|
app.run(debug=False, host='127.0.0.1', port=port)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|