-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
50 lines (36 loc) · 1.31 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import time
import json
from gevent.pywsgi import WSGIServer
from flask import Flask, Response, render_template, stream_with_context
from gevent import monkey
monkey.patch_all()
"""
Flask server for the web interface
The data is read from lyrics.json and streamed from the server to the client
"""
app = Flask(__name__)
##############################
@app.route("/")
def render_index():
return render_template("neon.html")
##############################
@app.route("/listen")
def listen():
def respond_to_client():
while True:
with open("lyrics.json", "r") as f:
song_info = json.load(f)["data"]
print(song_info)
_data = json.dumps(
{"title": song_info["title"],
"lyrics": song_info["lyrics"],
"id": f"https://open.spotify.com/embed/track/{song_info['id']}"
})
yield f"id: 1\ndata: {_data}\nevent: online\n\n"
time.sleep(0.5)
return Response(respond_to_client(), mimetype='text/event-stream')
##############################
if __name__ == "__main__": #run the server
# app.run(port=80, debug=True)
http_server = WSGIServer(("localhost", 80), app)
http_server.serve_forever()