forked from bharath2020/SmartHome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temperature_server.py
61 lines (44 loc) · 1.37 KB
/
temperature_server.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
#!/usr/bin/env python3
from flask import Flask, request, render_template
import os
import json
import time
import datetime
from smarthomemongo import SmartHomeDB
app = Flask(__name__)
smartDB = SmartHomeDB()
@app.route('/')
def index():
records = smartDB.getCurrentStats('raspberry')
if( 'timestamp' in records.keys() ):
ts = datetime.datetime.fromtimestamp(records['timestamp']).strftime('%Y-%m-%d %H:%M:%S')
records['timestamp_string'] = ts
return render_template('index.html',records=records)
@app.route('/add', methods=['POST'])
def add():
recordJson = request.get_json()
smartDB.insertTemperaturePoint(recordJson)
return 'Success', 200
@app.route('/update_stats', methods=['POST'])
def update_stats():
recordJson = request.get_json()
smartDB.updateCurrentStats(recordJson)
return 'Success', 200
@app.route('/get_current_stats',methods=['GET'])
def get_current_stats():
record = smartDB.getCurrentStats('raspberry')
return json.dumps(record)
@app.route('/line_graph')
def get_line_graph():
return render_template('graph.html')
@app.route('/data.csv')
def get_data_csv():
records = smartDB.getTemperaturePoints()
return json.dumps(records)
@app.route('/upload_test1', methods=['POST'])
def upload_test():
recordJson = request.get_json()
smartDB.upload_collection(recordJson)
return 'Success', 200
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True)