-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartmeat-api.py
69 lines (53 loc) · 1.23 KB
/
smartmeat-api.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import logging
from flask import Flask, request, jsonify, json, Response
app = Flask(__name__)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# TODO Data sync with web socket
on = True
sticks = {
"stick1": {
"active": True,
"time_active": "12:45"
},
"stick2": {
"active": True,
"time_active": "10:10"
},
"stick3": {
"active": False,
"time_active": "00:00"
},
"stick4": {
"active": False,
"time_active": "00:00"
}
}
temperature = 175
def sync_data():
global on
global sticks
global temperature
return on, sticks, temperature
def build_json():
logger.debug('Building JSON')
data = {}
on, sticks, temperature = sync_data()
data = {
'on': on,
'sticks': sticks,
'temperature': temperature,
}
with app.app_context():
result = jsonify(data)
return result
@app.route('/get_info', methods=['GET'])
def get_info():
data = build_json()
return data
# @app.route('/get_temperature', methods=['GET'])
# def get_temperature():
# data = build_json()
# return data['temperature']
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, debug=True)