-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
36 lines (27 loc) · 869 Bytes
/
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
from flask import Flask, render_template, request, abort, redirect, url_for, flash, jsonify
import json
from Cat import Cat
from Population import Population
app = Flask(__name__)
app.config.from_object(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/cat', methods=['POST'])
def cat():
data = json.loads(request.data)
new_cat = Cat(name='test', **data)
new_cat.describe()
answer = jsonify(new_cat.serialize())
return answer
@app.route('/population', methods=['POST'])
def population():
data = json.loads(request.data)
population = Population()
for new_cat in data:
population.add_cat_from_data(new_cat)
next_population = population.breed_population()
answer = json.dumps(next_population.to_json())
return answer
if __name__ == '__main__':
app.run(debug=True)