-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
80 lines (65 loc) · 1.97 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from flask import Flask, request
import rethinkdb as r
import time
from datetime import datetime
import json
app = Flask(__name__)
conn = r.connect("192.168.6.26", 28015)
conn.use('hackiiitd')
@app.route('/')
def hello_world():
return "Welcome to jmprkableserver"
@app.route('/fall', methods=['GET'])
def fall():
timezone = time.strftime("%z")
reql_tz = r.make_timezone(timezone[:3] + ":" + timezone[3:])
the_date = datetime.now(reql_tz)
timestamp = time.mktime(the_date.timetuple())
json_date = the_date.isoformat()
r.table('fall').run(conn) # refers to r.db('marvel').table('heroes')
data = request.args.get('fallen')
''''
dataDict = json.loads(data)
try:
fallen = dataDict["fallen"]
except:
return("Invalid data")
'''
r.table("fall").insert({
"fallen": data,
'from_object': the_date,
'from_epoch': r.epoch_time(timestamp),
'from_iso': r.iso8601(json_date)
}).run(conn)
return "insertion successful"
@app.route('/medicine', methods=['GET'])
def medicine():
timezone = time.strftime("%z")
reql_tz = r.make_timezone(timezone[:3] + ":" + timezone[3:])
the_date = datetime.now(reql_tz)
timestamp = time.mktime(the_date.timetuple())
json_date = the_date.isoformat()
conn = r.connect("192.168.6.26", 28015)
data = request.data
dataDict = json.loads(data)
try:
status = dataDict["status"]
except:
return("Invalid data")
r.table("fall").insert({
"status": status,
'from_object': the_date,
'from_epoch': r.epoch_time(timestamp),
'from_iso': r.iso8601(json_date)
}).run(conn)
@app.route('/door', methods=['GET'])
def door():
r.table('door').run(conn)
status = request.args.get('status')
r.table("door").insert({
"door_id": 1,
"status": status
}, conflict="replace");
return "insertion successful"
if __name__ == "__main__":
app.run(port=8085, debug=False, host="0.0.0.0")