aboutsummaryrefslogtreecommitdiffstats
path: root/database.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-10-01 18:08:25 -0700
committerPinapelz <yukais@pinapelz.com>2025-10-01 18:08:25 -0700
commit63dd4995224db0540be1bca7a8f8d463483f8e43 (patch)
treec56f23eaeea1ff8b96c39909317da65db5f41059 /database.py
parent691a8a1c40f8f1357c09e8f2ac885865bbad6a5e (diff)
migrate summarizer, tl, wac modules to cache using db
Diffstat (limited to 'database.py')
-rw-r--r--database.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/database.py b/database.py
index a4e5ac9..0e1da81 100644
--- a/database.py
+++ b/database.py
@@ -14,6 +14,11 @@ class Database:
self._cursor.executescript(f.read())
self._conn.commit()
+ def close(self):
+ """Close the database connection"""
+ if self._conn:
+ self._conn.close()
+
def _migrate_old_data(self):
"""
Migrates old summarization, tl and wac files into DB
@@ -66,3 +71,34 @@ class Database:
(key, headline, content)
)
self._conn.commit()
+
+ def get_summary(self, key: str):
+ self._cursor.execute(
+ "SELECT headline, content FROM summarization WHERE id = ?",
+ (key,)
+ )
+ result = self._cursor.fetchone()
+ if result is None:
+ return None
+ return {"headline": result[0], "content": result[1]}
+
+ def get_translation(self, key: str):
+ self._cursor.execute(
+ "SELECT result FROM translation WHERE id = ?",
+ (key,)
+ )
+ result = self._cursor.fetchone()
+ if result is None:
+ return None
+ return result[0]
+
+ def get_wac_entry(self, key: str):
+ self._cursor.execute(
+ "SELECT isNews, type FROM wacplus WHERE id = ?",
+ (key,)
+ )
+ result = self._cursor.fetchone()
+ if result is None:
+ return None
+ is_news = True if result[0] == 1 else False
+ return is_news, result[1]
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage