cleanup
This commit is contained in:
@ -23,7 +23,9 @@ class InvalidResponseException(Exception):
|
||||
"""
|
||||
|
||||
class Genius:
|
||||
"""Genius Search Module"""
|
||||
"""
|
||||
Genius Search Module
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
self.label: str = "Genius"
|
||||
self.genius_url: str = private.GENIUS_URL
|
||||
@ -36,14 +38,15 @@ class Genius:
|
||||
self.redis_cache = redis_cache.RedisCache()
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
async def search(self, artist: str, song: str, **kwargs) -> Optional[LyricsResult]:
|
||||
async def search(self, artist: str, song: str,
|
||||
**kwargs) -> Optional[LyricsResult]:
|
||||
"""
|
||||
Genius Search
|
||||
Args:
|
||||
artist (str): the artist to search
|
||||
song (str): the song to search
|
||||
Returns:
|
||||
LyricsResult|None: The result, if found - None otherwise.
|
||||
Optional[LyricsResult]: The result, if found - None otherwise.
|
||||
"""
|
||||
try:
|
||||
# pylint: enable=unused-argument
|
||||
@ -59,7 +62,10 @@ class Genius:
|
||||
timeout=self.timeout,
|
||||
headers=self.headers) as request:
|
||||
request.raise_for_status()
|
||||
text: str|None = await request.text()
|
||||
text: Optional[str] = await request.text()
|
||||
|
||||
if not text:
|
||||
raise InvalidResponseException("No search response.")
|
||||
|
||||
if len(text) < 100:
|
||||
raise InvalidResponseException("Search response text was invalid (len < 100 chars.)")
|
||||
@ -94,14 +100,17 @@ class Genius:
|
||||
timeout=self.timeout,
|
||||
headers=self.headers) as scrape_request:
|
||||
scrape_request.raise_for_status()
|
||||
scrape_text: str|None = await scrape_request.text()
|
||||
scrape_text: Optional[str] = await scrape_request.text()
|
||||
|
||||
if not scrape_text:
|
||||
raise InvalidResponseException("No scrape response.")
|
||||
|
||||
if len(scrape_text) < 100:
|
||||
raise InvalidResponseException("Scrape response was invalid (len < 100 chars.)")
|
||||
|
||||
|
||||
html = BeautifulSoup(htm.unescape(scrape_text).replace('<br/>', '\n'), "html.parser")
|
||||
divs: ResultSet|None = html.find_all("div", {"data-lyrics-container": "true"})
|
||||
divs: Optional[ResultSet] = html.find_all("div", {"data-lyrics-container": "true"})
|
||||
|
||||
if not divs:
|
||||
return
|
||||
@ -124,8 +133,5 @@ class Genius:
|
||||
await self.redis_cache.increment_found_count(self.label)
|
||||
await self.cache.store(matched)
|
||||
return matched
|
||||
|
||||
except:
|
||||
# if log_level == "DEBUG":
|
||||
traceback.print_exc()
|
||||
return
|
||||
traceback.print_exc()
|
Reference in New Issue
Block a user