cleanup
This commit is contained in:
@ -2,18 +2,20 @@
|
||||
# pylint: disable=bare-except, broad-exception-caught, invalid-name
|
||||
|
||||
import time
|
||||
import logging
|
||||
from typing import Optional
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
import redis.asyncio as redis
|
||||
from lyric_search.sources import private, cache as LyricsCache, redis_cache
|
||||
|
||||
class Misc(FastAPI):
|
||||
"""Misc Endpoints"""
|
||||
def __init__(self, app: FastAPI, my_util, constants, radio): # pylint: disable=super-init-not-called
|
||||
self.app = app
|
||||
def __init__(self, app: FastAPI, my_util,
|
||||
constants, radio) -> None: # pylint: disable=super-init-not-called
|
||||
self.app: FastAPI = app
|
||||
self.util = my_util
|
||||
self.constants = constants
|
||||
self.radio_pubkey: str = "XC-AJCJS89-AOLOFKZ92921AK-AKASKZJAN178-3D1"
|
||||
self.lyr_cache = LyricsCache.Cache()
|
||||
self.redis_cache = redis_cache.RedisCache()
|
||||
self.redis_client = redis.Redis(password=private.REDIS_PW)
|
||||
@ -44,7 +46,7 @@ class Misc(FastAPI):
|
||||
return artistsong
|
||||
|
||||
|
||||
async def homepage_redis_widget(self) -> dict:
|
||||
async def homepage_redis_widget(self) -> JSONResponse:
|
||||
"""Homepage Redis Widget Handler"""
|
||||
|
||||
# Measure response time w/ test lyric search
|
||||
@ -58,33 +60,44 @@ class Misc(FastAPI):
|
||||
num_ci_keys = len(ci_keys)
|
||||
index_info = await self.redis_client.ft().info()
|
||||
indexed_lyrics: int = index_info.get('num_docs')
|
||||
return {
|
||||
return JSONResponse(content={
|
||||
'responseTime': round(response_time, 7),
|
||||
'storedKeys': total_keys,
|
||||
'indexedLyrics': indexed_lyrics,
|
||||
'sessions': num_ci_keys,
|
||||
}
|
||||
|
||||
async def homepage_sqlite_widget(self) -> dict:
|
||||
})
|
||||
|
||||
async def homepage_sqlite_widget(self) -> JSONResponse:
|
||||
"""Homepage SQLite Widget Handler"""
|
||||
|
||||
row_count: int = await self.lyr_cache.sqlite_rowcount()
|
||||
distinct_artists: int = await self.lyr_cache.sqlite_distinct("artist")
|
||||
lyrics_length: int = await self.lyr_cache.sqlite_lyrics_length()
|
||||
return {
|
||||
return JSONResponse(content={
|
||||
'storedRows': row_count,
|
||||
'distinctArtists': distinct_artists,
|
||||
'lyricsLength': lyrics_length,
|
||||
}
|
||||
})
|
||||
|
||||
async def homepage_lyrics_widget(self) -> dict:
|
||||
"""Homepage Lyrics Widget Handler"""
|
||||
|
||||
return await self.redis_cache.get_found_counts()
|
||||
found_counts: dict = await self.redis_cache.get_found_counts()
|
||||
if not isinstance(found_counts, dict):
|
||||
return {
|
||||
'err': True,
|
||||
'errorText': 'General failure.',
|
||||
}
|
||||
logging.info("Found: %s", found_counts)
|
||||
return found_counts
|
||||
|
||||
async def homepage_radio_widget(self) -> dict:
|
||||
async def homepage_radio_widget(self) -> JSONResponse:
|
||||
"""Homepage Radio Widget Handler"""
|
||||
|
||||
return {
|
||||
radio_np: str = await self.get_radio_np()
|
||||
if not radio_np:
|
||||
return JSONResponse(status_code=500, content={
|
||||
'err': True,
|
||||
'errorText': 'General failure.',
|
||||
})
|
||||
return JSONResponse(content={
|
||||
'now_playing': await self.get_radio_np(),
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user