diff options
| author | jwansek <eddie.atten.ea29@gmail.com> | 2026-03-24 18:33:56 +0000 |
|---|---|---|
| committer | jwansek <eddie.atten.ea29@gmail.com> | 2026-03-24 18:33:56 +0000 |
| commit | 4303ff93359c42e61cb7362932a4433d4d51cf1b (patch) | |
| tree | c82b6dd3240f28158da924e0c7c8ea5d5bcb0262 /edaweb/database.py | |
| parent | d0d10ab1c7179ab15a440f711909765140436851 (diff) | |
| download | boymoder.blog-4303ff93359c42e61cb7362932a4433d4d51cf1b.tar.gz boymoder.blog-4303ff93359c42e61cb7362932a4433d4d51cf1b.zip | |
Added page for each question
Diffstat (limited to 'edaweb/database.py')
| -rw-r--r-- | edaweb/database.py | 22 |
1 files changed, 21 insertions, 1 deletions
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)) |
