-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
28 lines (21 loc) · 667 Bytes
/
app.py
File metadata and controls
28 lines (21 loc) · 667 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
import io
from flask import Response, Flask, request, jsonify
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from utils import create_line_graph
app = Flask(__name__)
@app.route('/')
def index():
return 'hello there'
@app.route('/graph/line', methods=['POST'])
def line_chart():
try:
data = request.json
fig = create_line_graph(data)
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
except Exception as err:
data = {"error": str(err)}
return jsonify(data)
if __name__ == '__main__':
app.run()