From 4303ff93359c42e61cb7362932a4433d4d51cf1b Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 24 Mar 2026 18:33:56 +0000 Subject: Added page for each question --- edaweb/database.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'edaweb/database.py') diff --git a/edaweb/database.py b/edaweb/database.py index c6553a6..47e0f18 100644 --- a/edaweb/database.py +++ b/edaweb/database.py @@ -244,7 +244,27 @@ class Database: with self.__connection.cursor() as cursor: cursor.execute("SELECT * FROM qnas;") return sorted(cursor.fetchall(), key = operator.itemgetter(2), reverse = True) - + + def get_qna(self, id_): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT * FROM `qnas` WHERE `curiouscat_id` = %s;", (id_, )) + qna = {"qna": list(cursor.fetchone())} + cursor.execute("SELECT `curiouscat_id` FROM `qnas` WHERE `timestamp` < %s ORDER BY `timestamp` DESC LIMIT 1;", (qna["qna"][2], )) + try: + qna["previous"] = cursor.fetchone()[0] + except TypeError: + qna["previous"] = None + cursor.execute("SELECT `curiouscat_id` FROM `qnas` WHERE `timestamp` > %s ORDER BY `timestamp` LIMIT 1;", (qna["qna"][2], )) + try: + qna["next"] = cursor.fetchone()[0] + except TypeError: + qna["next"] = None + + return qna + +if __name__ == "__main__": + with Database() as db: + print(db.get_qna(1098140963)) -- cgit v1.2.3