UPDATE: Fix to stream/userpage routing, Added UserPage and Tidy to code;
Added ability to visit a user's profile page from their stream; Cleaned up code formatting, primarily changing from single quotes to double quotes; Removed unused SignupForm component;
This commit is contained in:
@@ -92,22 +92,22 @@ def get_streamer_data(streamer_username):
|
||||
@stream_bp.route('/streamer/<string:streamer_username>/status')
|
||||
def get_streamer_status(streamer_username):
|
||||
"""
|
||||
Returns a streamer's status, if they are live or not and their most recent stream
|
||||
Returns a streamer's status, if they are live or not and their most recent stream (their current stream if live)
|
||||
"""
|
||||
user_id = get_user_id(streamer_username)
|
||||
|
||||
if not user_id:
|
||||
abort(404)
|
||||
|
||||
is_live = streamer_live_status(user_id)
|
||||
most_recent_stream = streamer_most_recent_stream(user_id)
|
||||
is_live = True if streamer_live_status(user_id)['isLive'] else False
|
||||
most_recent_stream = streamer_most_recent_stream(user_id)['stream_id']
|
||||
|
||||
if not most_recent_stream:
|
||||
most_recent_stream = {'stream_id': None}
|
||||
most_recent_stream = None
|
||||
|
||||
return jsonify({
|
||||
"is_live": is_live,
|
||||
"most_recent_stream": most_recent_stream['stream_id']
|
||||
"most_recent_stream": most_recent_stream
|
||||
})
|
||||
|
||||
|
||||
@@ -122,6 +122,20 @@ def get_stream(streamer_username):
|
||||
|
||||
return jsonify(streamer_most_recent_stream(user_id))
|
||||
|
||||
|
||||
@stream_bp.route('/get_stream_data/<string:streamer_username>/<int:stream_id>')
|
||||
def get_specific_stream(streamer_username, stream_id):
|
||||
"""
|
||||
Returns a streamer's stream data given stream_id
|
||||
"""
|
||||
user_id = get_user_id(streamer_username)
|
||||
stream = user_stream(user_id, stream_id)
|
||||
if stream:
|
||||
return jsonify(stream)
|
||||
|
||||
return jsonify({'error': 'Stream not found'}), 404
|
||||
|
||||
|
||||
@login_required
|
||||
@stream_bp.route('/get_followed_category_streams')
|
||||
def get_following_categories_streams():
|
||||
@@ -136,18 +150,6 @@ def get_following_categories_streams():
|
||||
return jsonify(streams)
|
||||
|
||||
|
||||
@stream_bp.route('/get_stream_data/<string:streamer_username>/<int:stream_id>')
|
||||
def get_specific_stream(streamer_username, stream_id):
|
||||
"""
|
||||
Returns a streamer's stream data given stream_id
|
||||
"""
|
||||
user_id = get_user_id(streamer_username)
|
||||
stream = user_stream(user_id, stream_id)
|
||||
if stream:
|
||||
return jsonify(stream)
|
||||
|
||||
return jsonify({'error': 'Stream not found'}), 404
|
||||
|
||||
@login_required
|
||||
@stream_bp.route('/get_followed_streamers')
|
||||
def get_followed_streamers():
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from database.database import Database
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
def user_recommendation_category(user_id: int) -> Optional[int]:
|
||||
"""
|
||||
Queries user_preferences database to find users favourite streaming category and returns the category
|
||||
@@ -15,7 +16,8 @@ def user_recommendation_category(user_id: int) -> Optional[int]:
|
||||
""", (user_id,))
|
||||
return category["category_id"] if category else None
|
||||
|
||||
def followed_categories_recommendations(user_id : int) -> Optional[List[dict]]:
|
||||
|
||||
def followed_categories_recommendations(user_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Returns top 25 streams given a users category following
|
||||
"""
|
||||
@@ -31,6 +33,7 @@ def followed_categories_recommendations(user_id : int) -> Optional[List[dict]]:
|
||||
""", (user_id,))
|
||||
return streams
|
||||
|
||||
|
||||
def recommendations_based_on_category(category_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Queries stream database to get top 25 most viewed streams based on given category
|
||||
@@ -58,11 +61,13 @@ def default_recommendations() -> Optional[List[dict]]:
|
||||
FROM streams
|
||||
JOIN users ON users.user_id = streams.user_id
|
||||
JOIN categories ON streams.category_id = categories.category_id
|
||||
WHERE isLive = 1
|
||||
ORDER BY num_viewers DESC
|
||||
LIMIT 25;
|
||||
""")
|
||||
return data
|
||||
|
||||
|
||||
def category_recommendations() -> Optional[List[dict]]:
|
||||
"""
|
||||
Returns a list of the top 5 most popular live categories
|
||||
@@ -79,6 +84,7 @@ def category_recommendations() -> Optional[List[dict]]:
|
||||
""")
|
||||
return categories
|
||||
|
||||
|
||||
def user_category_recommendations(user_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Queries user_preferences database to find users top 5 favourite streaming category and returns the category
|
||||
@@ -92,4 +98,4 @@ def user_category_recommendations(user_id: int) -> Optional[List[dict]]:
|
||||
ORDER BY favourability DESC
|
||||
LIMIT 5
|
||||
""", (user_id,))
|
||||
return categories
|
||||
return categories
|
||||
|
||||
@@ -45,29 +45,6 @@ def followed_streamers(user_id: int) -> Optional[List[dict]]:
|
||||
""", (user_id,))
|
||||
return followed_streamers
|
||||
|
||||
def streamer_most_recent_stream(user_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns data of the most recent stream by a streamer
|
||||
"""
|
||||
with Database() as db:
|
||||
most_recent_stream = db.fetchone("""
|
||||
SELECT * FROM streams
|
||||
WHERE user_id = ?
|
||||
AND stream_id = (SELECT MAX(stream_id) FROM streams WHERE user_id = ?)
|
||||
""", (user_id, user_id))
|
||||
return most_recent_stream
|
||||
|
||||
def streamer_data(streamer_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns information about the streamer
|
||||
"""
|
||||
with Database() as db:
|
||||
data = db.fetchone("""
|
||||
SELECT username, num_followering, isPartnered FROM users
|
||||
WHERE user_id = ?
|
||||
""", (streamer_id))
|
||||
return data
|
||||
|
||||
def user_stream(user_id: int, stream_id: int) -> dict:
|
||||
"""
|
||||
Returns data of a streamers selected stream
|
||||
@@ -83,6 +60,32 @@ def user_stream(user_id: int, stream_id: int) -> dict:
|
||||
""", (user_id, stream_id))
|
||||
return stream
|
||||
|
||||
def streamer_most_recent_stream(user_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns data of the most recent stream by a streamer
|
||||
"""
|
||||
with Database() as db:
|
||||
most_recent_stream = db.fetchone("""
|
||||
SELECT s.stream_id, u.username, s.user_id, s.title, s.start_time, s.num_viewers, c.category_name
|
||||
FROM streams AS s
|
||||
JOIN categories AS c ON s.category_id = c.category_id
|
||||
JOIN users AS u ON s.user_id = u.user_id
|
||||
WHERE u.user_id = ?
|
||||
AND s.stream_id = (SELECT MAX(stream_id) FROM streams WHERE user_id = ?)
|
||||
""", (user_id, user_id))
|
||||
return most_recent_stream
|
||||
|
||||
def streamer_data(streamer_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns information about the streamer
|
||||
"""
|
||||
with Database() as db:
|
||||
data = db.fetchone("""
|
||||
SELECT username, bio, num_followers, is_partnered FROM users
|
||||
WHERE user_id = ?
|
||||
""", (streamer_id,))
|
||||
return data
|
||||
|
||||
def generate_thumbnail(user_id: int) -> None:
|
||||
"""
|
||||
Returns the thumbnail of a stream
|
||||
|
||||
Reference in New Issue
Block a user