aboutsummaryrefslogtreecommitdiffstats
path: root/edaweb/database.py
diff options
context:
space:
mode:
Diffstat (limited to 'edaweb/database.py')
-rw-r--r--edaweb/database.py22
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))