non.
This commit is contained in:
parent
29fce1215d
commit
ab74f5b642
30
Flask/app.py
30
Flask/app.py
|
@ -12,19 +12,21 @@ import json
|
||||||
import re
|
import re
|
||||||
from requests import get
|
from requests import get
|
||||||
import redis
|
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
|
# the end
|
||||||
|
|
||||||
|
@ -124,7 +126,6 @@ def inject_default_variables():
|
||||||
#Login stuff
|
#Login stuff
|
||||||
"""
|
"""
|
||||||
# config
|
# config
|
||||||
app.config["REDIS_URL"] = "redis://localhost"
|
|
||||||
app.config["TEMPLATES_AUTO_RELOAD"] = True
|
app.config["TEMPLATES_AUTO_RELOAD"] = True
|
||||||
app.config.update(
|
app.config.update(
|
||||||
SECRET_KEY = secret
|
SECRET_KEY = secret
|
||||||
|
@ -146,8 +147,9 @@ class User(UserMixin):
|
||||||
|
|
||||||
users = [User(1)]
|
users = [User(1)]
|
||||||
|
|
||||||
|
@app.route('/stream')
|
||||||
app.register_blueprint(sse, url_prefix='/stream')
|
def stream():
|
||||||
|
return Response(generate_output(), content_type='text/event-stream')
|
||||||
|
|
||||||
|
|
||||||
@app.route("/login/", methods=["GET", "POST"])
|
@app.route("/login/", methods=["GET", "POST"])
|
||||||
|
|
Loading…
Reference in New Issue