Implemented some stream routes (needs code review, cant properly test at work)

This commit is contained in:
ThisBirchWood
2025-01-28 09:48:57 +00:00
parent 7b511677c9
commit 46a8895398

View File

@@ -1,6 +1,7 @@
from flask import Blueprint, session from flask import Blueprint, session
from utils.stream_utils import streamer_data, streamer_id, streamer_live_status, streamer_most_recent_stream, streamer_stream, followed_live_streams from utils.stream_utils import streamer_data, streamer_id, streamer_live_status, streamer_most_recent_stream, streamer_stream, followed_live_streams
from utils.user_utils import get_user_id from utils.user_utils import get_user_id
from database.database import Database
stream_bp = Blueprint("stream", __name__) stream_bp = Blueprint("stream", __name__)
@@ -15,43 +16,14 @@ def get_sample_streams() -> list[dict]:
# user attains tags from the tags of the streamers they follow, and streamers they've watched # user attains tags from the tags of the streamers they follow, and streamers they've watched
# TODO Add a category field to the stream object # TODO Add a category field to the stream object
streams = [ db = Database()
{ cursor = db.create_connection()
"id": 1,
"title": "Gaming Stream", # fetch top 25 most viewed live streams if not logged in
"streamer": "Gamer123", # TODO Add a check to see if user is logged in, if they are, find streams that match categories they follow
"viewers": 1500, streams = cursor.execute("""SELECT * FROM streams
"thumbnail": "dance_game.png", ORDER BY num_viewers DESC
}, LIMIT 25; """).fetchall()
{
"id": 2,
"title": "Art Stream",
"streamer": "Artist456",
"viewers": 800,
"thumbnail": "surface.jpeg",
},
{
"id": 3,
"title": "Music Stream",
"streamer": "Musician789",
"viewers": 2000,
"thumbnail": "monkey.png",
},
{
"id": 4,
"title": "Just Chatting",
"streamer": "Chatty101",
"viewers": 1200,
"thumbnail": "chatting_category.jpg",
},
{
"id": 5,
"title": "Cooking Stream",
"streamer": "Chef202",
"viewers": 1000,
"thumbnail": "cooking_category.jpg",
}
]
return streams return streams
@@ -88,38 +60,18 @@ def get_categories() -> list[dict]:
""" """
Returns a list of (sample) categories being watched right now Returns a list of (sample) categories being watched right now
""" """
return [
{ db = Database()
"id": 1, cursor = db.create_connection()
"title": "Gaming",
"viewers": 220058, # fetch top categories by number of viewers
"thumbnail": "gaming_category.jpg", categories = cursor.execute("""SELECT category_name, SUM(num_viewers) FROM categories, streams
}, WHERE categories.category_id = streams.category_id
{ GROUP BY category_name
"id": 2, ORDER BY SUM(num_viewers) DESC
"title": "Music", LIMIT 25; """).fetchall()
"viewers": 150060, return categories
"thumbnail": "music_category.webp",
},
{
"id": 3,
"title": "Art",
"viewers": 10200,
"thumbnail": "art_category.jpg",
},
{
"id": 4,
"title": "Cooking",
"viewers": 8000,
"thumbnail": "cooking_category.jpg",
},
{
"id": 5,
"title": "Just Chatting",
"viewers": 83900,
"thumbnail": "chatting_category.jpg",
}
]
@stream_bp.route('/get_followed_categories') @stream_bp.route('/get_followed_categories')