forked from sambev/to-the-moon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
65 lines (51 loc) · 1.36 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
from flask import Flask, request, Response
from config.jinjacfg import render
import json
app = Flask(__name__)
from config.dev import config
app.config.update(config)
app.team = {
"id": 1,
"name": "Startup Weekend",
"goal_miles": 1200,
"users": [
{
"id": 1,
"name": "sam",
"distance": 0
},
{
"id": 2,
"name": "dean",
"distance": 0
},
{
"id": 3,
"name": "steve",
"distance": 0
}
]
}
@app.route("/")
def index():
return render('index.html')
@app.route('/users/', methods=['PUT'])
def users():
if request.method == 'PUT':
req_data = json.loads(request.data)
print request.data
# normal distance to a float
req_data['distance'] = float(req_data['distance'])
for user in app.team['users']:
if user['name'] == req_data['name']:
user['distance'] += float(req_data['distance'])
return Response(json.dumps(user), status=201)
app.team['users'].append(req_data)
return Response(json.dumps(req_data), status=201)
@app.route('/teams/', methods=['GET'])
def teams():
if request.method == 'GET':
print app.team
return Response(json.dumps(app.team))
if __name__ == "__main__":
app.run()