51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
|
import eventlet
|
||
|
eventlet.monkey_patch()
|
||
|
import configparser
|
||
|
import json
|
||
|
import os
|
||
|
from eventlet import wsgi
|
||
|
|
||
|
from flask import Flask, render_template
|
||
|
from flask_socketio import SocketIO, emit
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
app.config['SECRET_KEY'] = 'secret!'
|
||
|
socketio = SocketIO(app, async_mode='eventlet', cors_allowed_origins="*")
|
||
|
# 读取配置文件
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read('config.ini', encoding="utf-8")
|
||
|
|
||
|
# 从配置文件中读取参数
|
||
|
host = config.get('web', 'host')
|
||
|
port = config.get('web', 'port')
|
||
|
key = config.get('web', 'key')
|
||
|
@app.route('/')
|
||
|
def index():
|
||
|
return render_template('index.html')
|
||
|
@app.route('/cjl')
|
||
|
def cjl():
|
||
|
return render_template('cjl.html')
|
||
|
@app.route('/1')
|
||
|
def user_1():
|
||
|
return render_template('cjl.html')
|
||
|
@socketio.on('connect')
|
||
|
def handle_connect():
|
||
|
print('Client connected')
|
||
|
|
||
|
@socketio.on('disconnect')
|
||
|
def handle_disconnect():
|
||
|
print('Client disconnected')
|
||
|
|
||
|
@socketio.on(key)
|
||
|
def handle_data_received(json_data):
|
||
|
print(key,':', json.loads(json_data)) # data: {'目标时间': 120, '目标工作量': 5, '未及格成员': [['', '', '', '', '', '', '', '', '', '', '', ''], ['王正生\n176****8037', '晚高峰', '-', '否', '下班', '0分钟', '0分钟', '0', '0分钟', '0分钟', '0', '0'], ['黄昆利\n136****5164', '晚高峰', '-', '否', '下班', '0分钟', '0分钟', '0', '0分钟', '0分钟', '0', '0']]}
|
||
|
|
||
|
# 把数据以表格形式更新再html里面
|
||
|
emit('update_table_'+key, json.loads(json_data), broadcast=True)
|
||
|
# 在这里处理接收到的数据
|
||
|
@socketio.on('log_'+key)
|
||
|
def handle_data_received(json_data):
|
||
|
print('log:', json.dumps(json_data))
|
||
|
# 在这里处理接收到的数据
|
||
|
if __name__ == '__main__':
|
||
|
wsgi.server(eventlet.listen((host, int(os.environ.get('PORT', int(port))))), app)
|