Created utils folder which holds funcs to be called within the flask routes, added pseudo code to streams.py and user.py which are untested, data still needs to be jsonified to be sent to React

This commit is contained in:
JustIceO7
2025-01-26 06:51:24 +00:00
parent 64a5bf6f82
commit ff9feaacec
6 changed files with 251 additions and 37 deletions

View File

@@ -0,0 +1,26 @@
from database.database import Database
from user_utils import get_user_id
from typing import Optional, List, Tuple
def user_recommendation_category(username: str) -> Optional[int]:
"""
Queries user_preferences database to find users favourite streaming category and returns the category
"""
db = Database()
cursor = db.create_connection()
user_id = get_user_id(username)
data = cursor.execute(
"SELECT category_id FROM user_preferences WHERE user_id = ? ORDER BY favourability DESC LIMIT 1", (user_id,)).fetchone()
return data[0]
def recommendations_based_on_category(category_id: int) -> Optional[List[Tuple[int, str, int]]]:
"""
Queries stream database to get top 10 most viewed streams based on given category and returns (stream_id, title, num_viewers)
"""
db = Database()
cursor = db.create_connection()
data = cursor.execute(
"SELECT streamer_id, stream_id, title, num_viewers FROM streams WHERE category_id = ? ORDER BY num_viwers DESC LIMIT 10", (category_id,)).fetchall()
return data