diff --git a/Flask/app.py b/Flask/app.py index 22c28ce..dce151d 100644 --- a/Flask/app.py +++ b/Flask/app.py @@ -12,19 +12,21 @@ import json import re from requests import get import redis -from flask_sse import sse -## redis part for live update -#redis_client = redis.StrictRedis(host='127.0.0.1', port=6379, db=0) -#pubsub = redis_client.pubsub() -#pubsub.subscribe('console') -# -#def generate_output(): -# for message in pubsub.listen(): -# if message['type'] == 'message': -# print(message) -# yield f"data: {message['data'].decode()}\n\n" +# redis part for live update +redis_client = redis.StrictRedis(host='127.0.0.1', port=6379, db=0) +pubsub = redis_client.pubsub() +pubsub.subscribe('console') + +def generate_output(): + try : + for message in pubsub.listen(): + if message['type'] == 'message': + print(message) + yield f"data: {message['data'].decode()}\n\n" + except : + print("ya eu une erreur sad") # the end @@ -124,7 +126,6 @@ def inject_default_variables(): #Login stuff """ # config -app.config["REDIS_URL"] = "redis://localhost" app.config["TEMPLATES_AUTO_RELOAD"] = True app.config.update( SECRET_KEY = secret @@ -146,8 +147,9 @@ class User(UserMixin): users = [User(1)] - -app.register_blueprint(sse, url_prefix='/stream') +@app.route('/stream') +def stream(): + return Response(generate_output(), content_type='text/event-stream') @app.route("/login/", methods=["GET", "POST"])