summaryrefslogtreecommitdiffstats
path: root/db.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-03-18 19:08:15 -0700
committerPinapelz <yukais@pinapelz.com>2026-03-18 19:08:15 -0700
commit44face929d3e1e4a964dd4f948acf34cfd5e3c55 (patch)
tree3acf0f1d4c25d41a7e246d109a3f641a3536e517 /db.py
parent9a4561069ea3a794f1d66d0b2ff04d8d1ff20411 (diff)
feat: view game by idx rng
Diffstat (limited to 'db.py')
-rw-r--r--db.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/db.py b/db.py
index 5116708..8e01b82 100644
--- a/db.py
+++ b/db.py
@@ -119,6 +119,25 @@ def remove_item(category: str, name: str) -> str | None:
return actual_name
+def count_items(category: str) -> int:
+ with _get_conn() as conn:
+ row = conn.execute(
+ "SELECT COUNT(*) AS cnt FROM items WHERE category = ?", (category,)
+ ).fetchone()
+ return row["cnt"]
+
+
+def get_item_by_index(category: str, index: int) -> sqlite3.Row | None:
+ with _get_conn() as conn:
+ rows = conn.execute(
+ "SELECT name, note, added_by FROM items WHERE category = ? ORDER BY id ASC",
+ (category,),
+ ).fetchall()
+ if not rows or index < 1 or index > len(rows):
+ return None
+ return rows[index - 1]
+
+
def find_item(category: str, keyword: str = "") -> sqlite3.Row | None:
"""Return a random item from the category, optionally filtered by keyword in note."""
keyword = keyword.strip().lower()
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage