aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/app.py7
-rw-r--r--api/database.py2
-rw-r--r--requirements.txtbin626 -> 76 bytes
3 files changed, 6 insertions, 3 deletions
diff --git a/api/app.py b/api/app.py
index e39d9a7..c34997f 100644
--- a/api/app.py
+++ b/api/app.py
@@ -4,6 +4,7 @@ from .database import PostgresHandler
import os
import secrets
from dotenv import load_dotenv
+import random
import urllib.parse
load_dotenv()
@@ -47,8 +48,10 @@ def generate_organization_captcha(org):
return jsonify({"error": "Database Connection Failed. Dynamic Affiliation Endpoint requires a PostgreSQL Connection"}), 500
if server.check_row_exists("vtuber_data", "affiliation", org) is False:
return jsonify({"error": "Organization " + org + " was not found in the database" }), 404
- correct_answers= server.get_random_row('vtuber_data', 5, "affiliation = '"+org+"'")
- random_answers = server.get_random_row('vtuber_data', 11)
+ num_correct = random.randint(5, 9)
+ num_wrong = 16 - num_correct
+ correct_answers= server.get_random_rows('vtuber_data', num_correct, "affiliation = '"+org+"'")
+ random_answers = server.get_random_rows('vtuber_data', num_wrong)
server.close_connection()
question_data = [{"image": question[3], "name": question[1], "affiliation": question[2], "id": question[0] } for question in correct_answers + random_answers]
if create_session:
diff --git a/api/database.py b/api/database.py
index 0f31a7d..a5d70e6 100644
--- a/api/database.py
+++ b/api/database.py
@@ -84,7 +84,7 @@ class PostgresHandler:
print(e)
return False
- def get_random_row(self, table_name: str, count: int, condition: str = None):
+ def get_random_rows(self, table_name: str, count: int, condition: str = None):
if condition is None:
condition = "1 = 1"
try:
diff --git a/requirements.txt b/requirements.txt
index 136e996..8ec491d 100644
--- a/requirements.txt
+++ b/requirements.txt
Binary files differ
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage