-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
57 lines (46 loc) · 1.27 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
55
56
57
import datetime
import flask
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
import json
import os
import sys
app = Flask(__name__)
CORS(app)
now = datetime.datetime.now()
#server initialisation
raulStatus = {
'open': False,
'date-time': now.isoformat(),
'user': u'Raul Seixas'
}
@app.route('/status/', methods=['GET'])
def get_items():
return jsonify(raulStatus)
@app.route('/status/checkin',methods=['POST'])
def check_in():
raulStatus['open'] = True
now = datetime.datetime.now()
raulStatus['date-time']=now.isoformat()
reqData = request.get_json(silent=True)
if (reqData != None):
raulStatus['user']=reqData['user']
else:
raulStatus['user']="Raul Seixas"
return jsonify(raulStatus)
@app.route('/status/checkout',methods=['POST'])
def check_out():
raulStatus['open'] = False
now = datetime.datetime.now()
raulStatus['date-time']=now.isoformat()
reqData = request.get_json(silent=True)
if (reqData != None):
raulStatus['user']=reqData['user']
else:
raulStatus['user']="Raul Seixas"
return jsonify(raulStatus)
@app.route("/")
def index():
return "Hello, there's nothing for you here!"
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0')