-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_server.py
48 lines (32 loc) · 864 Bytes
/
web_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
from flask import Flask, render_template
from werkzeug import SharedDataMiddleware
from helpers import getPlaylist
import os
app = Flask(__name__)
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
'/': os.path.join(os.path.dirname(__file__), 'static')
})
@app.route('/')
def main_page():
options = []
for item in getPlaylist():
dict = {}
dict['url'] = '/go/' + item
dict['text'] = item
options.append(dict)
return render_template('home.html', stations = options)
@app.route('/go/<station>')
def go_to_station(station):
fh = open('status', 'w')
fh.write(station)
fh.close()
return main_page()
@app.route('/playlist')
def see_playlist():
fh = open('playlist.json', 'rb')
output = fh.read()
fh.close()
return output
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')