-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (49 loc) · 1.75 KB
/
app.py
File metadata and controls
61 lines (49 loc) · 1.75 KB
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
import aikido_zen # Aikido package import
aikido_zen.protect()
import time
from flask import Flask, render_template, request
from flaskext.mysql import MySQL
app = Flask(__name__)
mysql = MySQL()
app.config['MYSQL_DATABASE_HOST'] = '127.0.0.1'
app.config['MYSQL_DATABASE_USER'] = 'user'
app.config['MYSQL_DATABASE_PASSWORD'] = 'password'
app.config['MYSQL_DATABASE_DB'] = 'db'
mysql.init_app(app)
@app.route("/")
def homepage():
cursor = mysql.get_db().cursor()
cursor.execute("SELECT * FROM db.dogs")
dogs = cursor.fetchall()
return render_template('index.html', title='Homepage', dogs=dogs)
@app.route('/dogpage/<int:dog_id>')
def get_dogpage(dog_id):
cursor = mysql.get_db().cursor()
cursor.execute("SELECT * FROM db.dogs WHERE id = " + str(dog_id))
dog = cursor.fetchmany(1)[0]
return render_template('dogpage.html', title=f'Dog', dog=dog, isAdmin=("Yes" if dog[2] else "No"))
@app.route("/create", methods=['GET'])
def show_create_dog_form():
return render_template('create_dog.html')
@app.route("/create", methods=['POST'])
def create_dog():
dog_name = request.form['dog_name']
connection = mysql.get_db()
cursor = connection.cursor()
cursor.execute(f'INSERT INTO dogs (dog_name, isAdmin) VALUES ("%s", 0)' % (dog_name))
connection.commit()
return f'Dog {dog_name} created successfully'
@app.route("/benchmark", methods=['GET'])
def benchmark():
time.sleep(1/1000)
return "OK"
@app.route("/benchmark_io", methods=['GET'])
def benchmark_io():
for i in range(50):
with open("benchmark_temp.txt", "w") as f:
f.write("This is a benchmark file.")
with open("benchmark_temp.txt", "r") as f:
content = f.read()
return "OK"
if __name__ == '__main__':
app.run()