-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (42 loc) · 1.6 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
50
51
52
53
54
from concurrent.futures import thread
from flask import Flask, render_template
import detector
app = Flask(__name__) # 绑定app
# 函数一:关联页面
@app.route('/') # 路由
def image():
return render_template('image.html')
@app.route('/temperature') # 路由
def image2():
return render_template('temperature.html')
# 函数二:生成数据
from flask import jsonify # 数据转为json,并以字典的形式传回前端
import datetime, random # 导入时间和随机数模块
@app.route('/setData/')
def setData():
while True:
print("hello world")
now = datetime.datetime.now().strftime('%H:%M:%S')
height = detector.detector()
data = {'time':now, 'data':height}
#data = {'time': now, 'data': random.randint(1, 10)}
return jsonify(data) # 将数据以字典的形式传回
@app.route('/setData1/')
def setData1():
while True:
now = datetime.datetime.now().strftime('%H:%M:%S')
temperature = detector.detector1()
data = {'time':now, 'data':temperature}
#data = {'time': now, 'data': random.randint(1, 10)}
return jsonify(data) # 将数据以字典的形式传回
# @app.route('/setData2/')
# def setDataTemperature():
# while True:
# print("hello world")
# now = datetime.datetime.now().strftime('%H:%M:%S')
# temperature = detector.temperatureDetecte()
# data = {'time':now, 'data':temperature}
# #data = {'time': now, 'data': random.randint(1, 10)}
# return jsonify(data) # 将数据以字典的形式传回
if __name__ == '__main__':
app.run()