From 07b245e3ff157b6543358cfb4fcb7c337510608e Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 8 Sep 2025 17:13:52 -0700 Subject: dynamic number of correct and wrong answers --- api/app.py | 7 +++++-- api/database.py | 2 +- requirements.txt | Bin 626 -> 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 Binary files a/requirements.txt and b/requirements.txt differ -- cgit v1.2.3