docstring stuff
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#!/usr/bin/env python3.12
|
||||
# pylint: disable=bare-except, broad-exception-caught
|
||||
# pylint: disable=bare-except, broad-exception-caught, wrong-import-order
|
||||
# pylint: disable=wrong-import-position
|
||||
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
import json
|
||||
import sys
|
||||
sys.path.insert(1,'..')
|
||||
from lyric_search_new import notifier
|
||||
import redis.asyncio as redis
|
||||
from redis.commands.search.query import Query
|
||||
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
|
||||
@@ -12,6 +16,7 @@ from redis.commands.search.field import TextField
|
||||
from . import private
|
||||
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
log_level = logging.getLevelName(logger.level)
|
||||
|
||||
@@ -27,6 +32,8 @@ class RedisCache:
|
||||
|
||||
def __init__(self):
|
||||
self.redis_client = redis.Redis(password=private.REDIS_PW)
|
||||
self.notifier = notifier.DiscordNotifier()
|
||||
self.notify_warnings = True
|
||||
|
||||
async def create_index(self):
|
||||
"""Create Index"""
|
||||
@@ -41,8 +48,8 @@ class RedisCache:
|
||||
schema, definition=IndexDefinition(prefix=["lyrics:"], index_type=IndexType.JSON))
|
||||
if str(result) != "OK":
|
||||
raise RedisException(f"Redis: Failed to create index: {result}")
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
await self.notifier.send(f"ERROR @ {__file__}", f"Failed to create idx: {str(e)}")
|
||||
|
||||
async def search(self, **kwargs):
|
||||
"""Search Redis Cache
|
||||
@@ -62,13 +69,13 @@ class RedisCache:
|
||||
raise RedisException("Lyric search not yet implemented")
|
||||
|
||||
if not is_random_search:
|
||||
artist = artist.replace("-", "")
|
||||
song = song.replace("-", "")
|
||||
artist = artist.replace("-", " ")
|
||||
song = song.replace("-", " ")
|
||||
search_res = await self.redis_client.ft().search(
|
||||
Query(f"@artist:{artist} @song:{song}"
|
||||
))
|
||||
search_res_out = [(result['id'].split(":",
|
||||
maxsplit=1)[1][:-1], dict(json.loads(result['json'])))
|
||||
maxsplit=1)[1], dict(json.loads(result['json'])))
|
||||
for result in search_res.docs]
|
||||
else:
|
||||
random_redis_key = await self.redis_client.randomkey()
|
||||
@@ -77,8 +84,10 @@ class RedisCache:
|
||||
search_res = await self.redis_client.json().get(random_redis_key)
|
||||
search_res_out = [(out_id, search_res)]
|
||||
|
||||
|
||||
if not search_res_out and self.notify_warnings:
|
||||
await self.notifier.send("WARNING", f"Redis cache miss for: \n## *{artist} - {song}*")
|
||||
return search_res_out
|
||||
except:
|
||||
except Exception as e:
|
||||
await self.notifier.send(f"ERROR @ {__file__}", str(e))
|
||||
traceback.print_exc()
|
||||
|
||||
Reference in New Issue
Block a user