forked from HritwikSinghal/Spark-tweet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (37 loc) · 1.31 KB
/
app.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
from os import truncate
import re
from flask import Flask, jsonify, request
from flask import render_template
import ast
app = Flask(__name__)
dataValues = []
categoryValues = []
@app.route("/")
def home():
return render_template('index.html',dataValues=dataValues,categoryValues=categoryValues)
@app.route('/refreshData')
def refresh_graph_data():
global dataValues, categoryValues
print("labels now: " + str(dataValues))
print("data now: " + str(categoryValues))
# dataValues[0]=dataValues[0]+1
return jsonify(dataValues=dataValues, categoryValues=categoryValues)
@app.route('/updateData', methods=['POST'])
def update_data_post():
global dataValues, categoryValues
if not request.form or 'data' not in request.form:
return "error", 400
categoryValues = ast.literal_eval(request.form['label'])
for i, ele in enumerate(categoryValues):
try:
new_ele = re.findall(r'bytearray\(b\'(#.*)\'\)', ele)[0]
print(new_ele)
categoryValues[i] = new_ele
except:
continue
dataValues = ast.literal_eval(request.form['data'])
print(f"labels received: {str(categoryValues)}")
print(f"data received: {str(dataValues)}")
return "success", 201
if __name__ == "__main__":
app.run(host='localhost', port=5001 , debug=True)