Fix/pylint cleanup (#8)
* Fix pylint warnings across all 24 Python files in web_server - Add module, class, and function docstrings (C0114, C0115, C0116) - Fix import ordering: stdlib before third-party before local (C0411) - Replace wildcard imports with explicit named imports (W0401) - Remove trailing whitespace and add missing final newlines (C0303, C0304) - Replace dict() with dict literals (R1735) - Remove unused imports and variables (W0611, W0612) - Narrow broad Exception catches to specific exceptions (W0718) - Replace f-string logging with lazy % formatting (W1203) - Fix variable naming: UPPER_CASE for constants, snake_case for locals (C0103) - Add pylint disable comments for necessary global statements (W0603) - Fix no-else-return, simplifiable-if-expression, singleton-comparison - Fix bad indentation in stripe.py (W0311) - Add encoding="utf-8" to open() calls (W1514) - Add check=True to subprocess.run() calls (W1510) - Register Celery task modules via conf.include * Update `package-lock.json` add peer dependencies
This commit is contained in:
committed by
GitHub
parent
fed1a2f288
commit
2758be8680
@@ -1,3 +1,5 @@
|
||||
"""Search bar blueprint for querying categories, users, streams, and VODs."""
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
from database.database import Database
|
||||
from utils.utils import sanitize
|
||||
@@ -20,7 +22,7 @@ def rank_results(query, result):
|
||||
# Assign a score based on the level of the match
|
||||
if query in result:
|
||||
return 0
|
||||
elif all(c in charset for c in query):
|
||||
if all(c in charset for c in query):
|
||||
return 1
|
||||
return 2
|
||||
|
||||
@@ -50,7 +52,7 @@ def search_results():
|
||||
res_dict.append(c)
|
||||
categories = sorted(res_dict, key=lambda d: d["score"])
|
||||
categories = categories[:4]
|
||||
|
||||
|
||||
# 3 users
|
||||
res_dict = []
|
||||
users = db.fetchall("SELECT user_id, username, is_live FROM users")
|
||||
@@ -63,7 +65,7 @@ def search_results():
|
||||
users = sorted(res_dict, key=lambda d: d["score"])
|
||||
users = users[:4]
|
||||
|
||||
# 3 streams
|
||||
# 3 streams
|
||||
res_dict = []
|
||||
streams = db.fetchall("""SELECT s.user_id, s.title, s.num_viewers, c.category_name, u.username
|
||||
FROM streams AS s
|
||||
@@ -71,7 +73,7 @@ def search_results():
|
||||
INNER JOIN users AS u ON s.user_id = u.user_id
|
||||
INNER JOIN categories AS c ON s.category_id = c.category_id
|
||||
""")
|
||||
|
||||
|
||||
for s in streams:
|
||||
key = s.get("title")
|
||||
score = rank_results(query.lower(), key.lower())
|
||||
@@ -83,7 +85,7 @@ def search_results():
|
||||
|
||||
# 3 VODs
|
||||
res_dict = []
|
||||
vods = db.fetchall("""SELECT v.vod_id, v.title, u.user_id, u.username
|
||||
vods = db.fetchall("""SELECT v.vod_id, v.title, u.user_id, u.username
|
||||
FROM vods as v JOIN users as u
|
||||
ON v.user_id = u.user_id""")
|
||||
for v in vods:
|
||||
@@ -98,5 +100,5 @@ def search_results():
|
||||
db.close_connection()
|
||||
|
||||
print(query, streams, users, categories, vods, flush=True)
|
||||
|
||||
return jsonify({"streams": streams, "categories": categories, "users": users, "vods": vods})
|
||||
|
||||
return jsonify({"streams": streams, "categories": categories, "users": users, "vods": vods})
|
||||
|
||||
Reference in New Issue
Block a user