-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathflask_server.py
More file actions
36 lines (28 loc) · 788 Bytes
/
flask_server.py
File metadata and controls
36 lines (28 loc) · 788 Bytes
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
import os
# PyPI
from flask import Flask, render_template, request
import device_info
import itunes_api
###
app = Flask(__name__)
# Index / search
@app.route('/', methods=['GET', 'POST'])
def index():
error = None
if request.method == 'GET':
data = None
if request.method == 'POST':
search_input = request.form['search']
data = itunes_api.search_album(search_input, 'album', 100)
if not data:
error = 'No search results for ' + search_input
return render_template('index.html', data=data, error=error)
# Info
@app.route('/info')
def show_info():
info = device_info.all_info()
return render_template('info.html', info=info)
# Launch server
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)