FEAT: CategoryPage updated to display streams;
General fixes and cleanup of unecessary logging; Update to 404 (NotFound) Page;
This commit is contained in:
@@ -31,6 +31,17 @@ def get_popular_streams(no_streams) -> list[dict]:
|
||||
streams = get_highest_view_streams(no_streams)
|
||||
return jsonify(streams)
|
||||
|
||||
@stream_bp.route('/streams/popular/<string:category_name>')
|
||||
def get_popular_streams_by_category(category_name) -> list[dict]:
|
||||
"""
|
||||
Returns a list of streams live now with the highest viewers in a given category
|
||||
"""
|
||||
|
||||
category_id = get_category_id(category_name)
|
||||
print(category_id, flush=True)
|
||||
streams = get_streams_based_on_category(category_id)
|
||||
return jsonify(streams)
|
||||
|
||||
@login_required
|
||||
@stream_bp.route('/streams/recommended')
|
||||
def get_recommended_streams() -> list[dict]:
|
||||
|
||||
@@ -19,7 +19,7 @@ def get_user_preferred_category(user_id: int) -> Optional[int]:
|
||||
|
||||
def followed_categories_recommendations(user_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Returns top 25 streams given a users category following
|
||||
Returns top 25 streams given a user's category following
|
||||
"""
|
||||
with Database() as db:
|
||||
streams = db.fetchall("""
|
||||
@@ -40,11 +40,11 @@ def get_streams_based_on_category(category_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
with Database() as db:
|
||||
streams = db.fetchall("""
|
||||
SELECT u.user_id, title, username, num_viewers, category_name
|
||||
FROM streams
|
||||
JOIN users u ON streams.user_id = u.user_id
|
||||
JOIN categories ON streams.category_id = categories.category_id
|
||||
WHERE categories.category_id = ?
|
||||
SELECT u.user_id, title, username, num_viewers, c.category_name
|
||||
FROM streams s
|
||||
JOIN users u ON s.user_id = u.user_id
|
||||
JOIN categories c ON s.category_id = c.category_id
|
||||
WHERE c.category_id = ?
|
||||
ORDER BY num_viewers DESC
|
||||
LIMIT 25
|
||||
""", (category_id,))
|
||||
|
||||
@@ -48,6 +48,18 @@ def get_current_stream_data(user_id: int) -> Optional[dict]:
|
||||
""", (user_id,))
|
||||
return most_recent_stream
|
||||
|
||||
def get_category_id(category_name: str) -> Optional[int]:
|
||||
"""
|
||||
Returns the category_id given a category name
|
||||
"""
|
||||
with Database() as db:
|
||||
data = db.fetchone("""
|
||||
SELECT category_id
|
||||
FROM categories
|
||||
WHERE category_name = ?;
|
||||
""", (category_name,))
|
||||
return data['category_id'] if data else None
|
||||
|
||||
def get_vod(vod_id: int) -> dict:
|
||||
"""
|
||||
Returns data of a streamers vod
|
||||
|
||||
Reference in New Issue
Block a user