from flask import Flask, render_template
from flask_socketio import SocketIO
from threading import Timer
from random import randint
 
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)


def generate_data():
    data = randint(0, 100)  # 示例数据，实际中可以是实时生成的数据
    socketio.emit('update', data)
    Timer(1, generate_data).start()  # 每1秒生成一次数据
 
@app.route('/')
def index():
    return render_template('index.html')
 
if __name__ == '__main__':
    generate_data()
    socketio.run(app, debug=True)
    
