|
1 | 1 | import aikido_zen # Aikido package import |
2 | 2 | aikido_zen.protect() |
3 | 3 |
|
4 | | -import os |
5 | 4 | from flask import Flask, render_template, request |
6 | | -import psycopg2 |
7 | 5 | import openai |
8 | 6 | from pydantic import BaseModel |
9 | 7 |
|
10 | 8 | app = Flask(__name__) |
11 | 9 | client = openai.OpenAI() |
12 | 10 |
|
13 | | -def get_db_connection(): |
14 | | - return psycopg2.connect( |
15 | | - host="localhost", |
16 | | - database="db", |
17 | | - user="user", |
18 | | - password="password") |
19 | | - |
20 | 11 | @app.route("/") |
21 | 12 | def homepage(): |
22 | | - cursor = get_db_connection().cursor() |
23 | | - cursor.execute("SELECT * FROM dogs") |
24 | | - dogs = cursor.fetchall() |
25 | | - return render_template('index.html', title='Homepage', dogs=dogs) |
26 | | - |
27 | | - |
28 | | -@app.route('/dogpage/<int:dog_id>') |
29 | | -def get_dogpage(dog_id): |
30 | | - cursor = get_db_connection().cursor() |
31 | | - cursor.execute("SELECT * FROM dogs WHERE id = " + str(dog_id)) |
32 | | - dog = cursor.fetchmany(1)[0] |
33 | | - return render_template('dogpage.html', title=f'Dog', dog=dog, isAdmin=("Yes" if dog[2] else "No")) |
34 | | - |
35 | | -@app.route("/create", methods=['GET']) |
36 | | -def show_create_dog_form(): |
37 | | - return render_template('create_dog.html') |
38 | | - |
39 | | -@app.route("/create_many", methods=['GET']) |
40 | | -def show_create_dog_form_many(): |
41 | | - return render_template('create_dog.html') |
42 | | - |
43 | | -@app.route("/create", methods=['POST']) |
44 | | -def create_dog(): |
45 | | - dog_name = request.form['dog_name'] |
46 | | - conn = get_db_connection() |
47 | | - cursor = conn.cursor() |
48 | | - cursor.execute(f"INSERT INTO dogs (dog_name, isAdmin) VALUES ('%s', FALSE)" % (dog_name)) |
49 | | - conn.commit() |
50 | | - cursor.close() |
51 | | - conn.close() |
52 | | - return f'Dog {dog_name} created successfully' |
| 13 | + return render_template('index.html', title='Homepage') |
53 | 14 |
|
54 | 15 | # OpenAI |
55 | 16 |
|
|
0 commit comments