diff options
| -rw-r--r-- | api/app.py | 7 | ||||
| -rw-r--r-- | api/database.py | 2 | ||||
| -rw-r--r-- | requirements.txt | bin | 626 -> 76 bytes |
3 files changed, 6 insertions, 3 deletions
@@ -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 Binary files differindex 136e996..8ec491d 100644 --- a/requirements.txt +++ b/requirements.txt |
