docstrings / formatting
This commit is contained in:
@@ -24,6 +24,7 @@ class Misc(FastAPI):
|
||||
"""
|
||||
|
||||
def __init__(self, app: FastAPI, my_util, constants, radio) -> None:
|
||||
"""Initialize Misc endpoints."""
|
||||
self.app: FastAPI = app
|
||||
self.util = my_util
|
||||
self.constants = constants
|
||||
@@ -84,12 +85,29 @@ class Misc(FastAPI):
|
||||
return "No."
|
||||
|
||||
async def no(self) -> JSONResponse:
|
||||
"""NaaS"""
|
||||
"""
|
||||
Get a random 'no' reason.
|
||||
|
||||
Returns:
|
||||
- **JSONResponse**: Contains a random 'no' reason.
|
||||
"""
|
||||
|
||||
return JSONResponse(content={"no": self.get_no()})
|
||||
|
||||
async def upload_activity_image(
|
||||
self, image: UploadFile, key: Annotated[str, Form()], request: Request
|
||||
) -> Response:
|
||||
"""
|
||||
Upload activity image.
|
||||
|
||||
Parameters:
|
||||
- **image** (UploadFile): The uploaded image file.
|
||||
- **key** (str): The API key for authentication.
|
||||
- **request** (Request): The HTTP request object.
|
||||
|
||||
Returns:
|
||||
- **Response**: Indicates success or failure of the upload.
|
||||
"""
|
||||
if (
|
||||
not key
|
||||
or not isinstance(key, str)
|
||||
@@ -112,6 +130,15 @@ class Misc(FastAPI):
|
||||
)
|
||||
|
||||
async def get_activity_image(self, request: Request) -> Response:
|
||||
"""
|
||||
Get the activity image.
|
||||
|
||||
Parameters:
|
||||
- **request** (Request): The HTTP request object.
|
||||
|
||||
Returns:
|
||||
- **Response**: The activity image or a fallback image.
|
||||
"""
|
||||
if isinstance(self.activity_image, bytes):
|
||||
return Response(content=self.activity_image, media_type="image/png")
|
||||
|
||||
@@ -125,11 +152,13 @@ class Misc(FastAPI):
|
||||
|
||||
async def get_radio_np(self, station: str = "main") -> tuple[str, str, str]:
|
||||
"""
|
||||
Get radio now playing
|
||||
Get radio now playing info.
|
||||
|
||||
Args:
|
||||
None
|
||||
station: Station name.
|
||||
|
||||
Returns:
|
||||
str: Radio now playing in artist - song format
|
||||
Tuple of (artistsong, album, genre).
|
||||
"""
|
||||
|
||||
np: dict = self.radio.radio_util.now_playing[station]
|
||||
@@ -145,7 +174,10 @@ class Misc(FastAPI):
|
||||
|
||||
async def homepage_redis_widget(self) -> JSONResponse:
|
||||
"""
|
||||
Homepage Redis Widget Handler
|
||||
Get Redis stats for homepage widget.
|
||||
|
||||
Returns:
|
||||
- **JSONResponse**: Contains Redis stats.
|
||||
"""
|
||||
# Measure response time w/ test lyric search
|
||||
time_start: float = time.time() # Start time for response_time
|
||||
@@ -169,7 +201,10 @@ class Misc(FastAPI):
|
||||
|
||||
async def homepage_rq_widget(self) -> JSONResponse:
|
||||
"""
|
||||
Homepage RQ Widget Handler
|
||||
Get RQ job stats for homepage widget.
|
||||
|
||||
Returns:
|
||||
- **JSONResponse**: Contains RQ job stats.
|
||||
"""
|
||||
queue_name = "dls"
|
||||
queue = Queue(queue_name, self.redis_client)
|
||||
@@ -193,7 +228,10 @@ class Misc(FastAPI):
|
||||
|
||||
async def homepage_sqlite_widget(self) -> JSONResponse:
|
||||
"""
|
||||
Homepage SQLite Widget Handler
|
||||
Get SQLite stats for homepage widget.
|
||||
|
||||
Returns:
|
||||
- **JSONResponse**: Contains SQLite stats.
|
||||
"""
|
||||
row_count: int = await self.lyr_cache.sqlite_rowcount()
|
||||
distinct_artists: int = await self.lyr_cache.sqlite_distinct("artist")
|
||||
@@ -208,7 +246,10 @@ class Misc(FastAPI):
|
||||
|
||||
async def homepage_lyrics_widget(self) -> JSONResponse:
|
||||
"""
|
||||
Homepage Lyrics Widget Handler
|
||||
Get lyrics stats for homepage widget.
|
||||
|
||||
Returns:
|
||||
- **JSONResponse**: Contains lyrics stats.
|
||||
"""
|
||||
found_counts: Optional[dict] = await self.redis_cache.get_found_counts()
|
||||
if not isinstance(found_counts, dict):
|
||||
@@ -228,7 +269,13 @@ class Misc(FastAPI):
|
||||
|
||||
async def homepage_radio_widget(self, station: str = "main") -> JSONResponse:
|
||||
"""
|
||||
Homepage Radio Widget Handler
|
||||
Get radio now playing for homepage widget.
|
||||
|
||||
Parameters:
|
||||
- **station** (str): Station name. Defaults to "main".
|
||||
|
||||
Returns:
|
||||
- **JSONResponse**: Contains now playing info.
|
||||
"""
|
||||
radio_np: tuple = await self.get_radio_np(station)
|
||||
if not radio_np:
|
||||
|
Reference in New Issue
Block a user