minor cleanup

This commit is contained in:
codey 2025-02-12 09:45:55 -05:00
parent 09dd9db970
commit ee8407a7e7
2 changed files with 14 additions and 14 deletions

View File

@ -2,6 +2,7 @@
import os import os
import random import random
from typing import LiteralString
import aiosqlite as sqlite3 import aiosqlite as sqlite3
from fastapi import FastAPI from fastapi import FastAPI
from .constructors import RandMsgRequest from .constructors import RandMsgRequest
@ -57,38 +58,38 @@ class RandMsg(FastAPI):
ORDER BY RANDOM() LIMIT 1" # For Trump Tweet DB ORDER BY RANDOM() LIMIT 1" # For Trump Tweet DB
title_attr = "Trump Tweet DB" title_attr = "Trump Tweet DB"
case 3: case 3:
randmsg_db_path = os.path.join("/", randmsg_db_path: str|LiteralString = os.path.join("/",
"usr", "local", "share", "usr", "local", "share",
"sqlite_dbs", "sqlite_dbs",
"philo.db") # For Philo DB "philo.db") # For Philo DB
db_query = "SELECT id, (content || '<br> - ' || speaker) FROM quotes \ db_query: str = "SELECT id, (content || '<br> - ' || speaker) FROM quotes \
ORDER BY RANDOM() LIMIT 1" # For Philo DB ORDER BY RANDOM() LIMIT 1" # For Philo DB
title_attr = "Philosophical Quotes DB" title_attr: str = "Philosophical Quotes DB"
case 4: case 4:
randmsg_db_path = os.path.join("/", randmsg_db_path: str|LiteralString = os.path.join("/",
"usr", "local", "share", "usr", "local", "share",
"sqlite_dbs", "sqlite_dbs",
"hate.db") # For Hate DB "hate.db") # For Hate DB
db_query = """SELECT id, ("<font color='#FF0000'>" || comment) FROM hate_speech \ db_query: str = """SELECT id, ("<font color='#FF0000'>" || comment) FROM hate_speech \
WHERE length(comment) <= 180 ORDER BY RANDOM() LIMIT 1""" WHERE length(comment) <= 180 ORDER BY RANDOM() LIMIT 1"""
title_attr = "Hate Speech DB" title_attr: str = "Hate Speech DB"
case 5: case 5:
randmsg_db_path = os.path.join("/", randmsg_db_path: str|LiteralString = os.path.join("/",
"usr", "local", "share", "usr", "local", "share",
"sqlite_dbs", "sqlite_dbs",
"rjokes.db") # r/jokes DB "rjokes.db") # r/jokes DB
db_query = """SELECT id, (title || "<br>" || body) FROM jokes \ db_query: str = """SELECT id, (title || "<br>" || body) FROM jokes \
WHERE score >= 10000 ORDER BY RANDOM() LIMIT 1""" WHERE score >= 10000 ORDER BY RANDOM() LIMIT 1"""
title_attr = "r/jokes DB" title_attr: str = "r/jokes DB"
case 6: case 6:
randmsg_db_path = os.path.join("/", randmsg_db_path: str|LiteralString = os.path.join("/",
"usr", "local", "share", "usr", "local", "share",
"sqlite_dbs", "sqlite_dbs",
"donnies.db") # Donnies DB "donnies.db") # Donnies DB
random.seed() random.seed()
twilight_or_mice = random.choice(["twilight", "mice"]) twilight_or_mice: str = random.choice(["twilight", "mice"])
db_query = f"SELECT id, text FROM {twilight_or_mice} ORDER BY RANDOM() LIMIT 1" db_query: str = f"SELECT id, text FROM {twilight_or_mice} ORDER BY RANDOM() LIMIT 1"
title_attr = "Donnies DB" title_attr: str = "Donnies DB"
async with sqlite3.connect(database=randmsg_db_path, timeout=1) as _db: async with sqlite3.connect(database=randmsg_db_path, timeout=1) as _db:
async with await _db.execute(db_query) as _cursor: async with await _db.execute(db_query) as _cursor:

View File

@ -26,7 +26,6 @@ class Transcriptions(FastAPI):
async def get_episodes_handler(self, data: ValidShowEpisodeListRequest) -> dict: async def get_episodes_handler(self, data: ValidShowEpisodeListRequest) -> dict:
"""Get list of episodes by show id""" """Get list of episodes by show id"""
show_id: int = data.s show_id: int = data.s
db_path: Optional[str|LiteralString] = None db_path: Optional[str|LiteralString] = None
db_query: Optional[str] = None db_query: Optional[str] = None