formatting/add meme endpoints

This commit is contained in:
2025-05-17 08:07:38 -04:00
parent d944a32c62
commit 2caa482a0d
10 changed files with 135 additions and 31 deletions

View File

@ -89,10 +89,8 @@ class Cache:
logging.debug(
"Checking whether %s is already stored", artistsong.replace("\n", " - ")
)
check_query: str = (
'SELECT id, artist, song FROM lyrics WHERE editdist3((lower(artist) || " " || lower(song)), (? || " " || ?))\
check_query: str = 'SELECT id, artist, song FROM lyrics WHERE editdist3((lower(artist) || " " || lower(song)), (? || " " || ?))\
<= 410 ORDER BY editdist3((lower(artist) || " " || lower(song)), ?) ASC LIMIT 1'
)
artistsong_split = artistsong.split("\n", maxsplit=1)
artist = artistsong_split[0].lower()
song = artistsong_split[1].lower()
@ -213,8 +211,10 @@ class Cache:
lyrics = regex.sub(r"(<br>|\n|\r\n)", " / ", lyr_result.lyrics.strip())
lyrics = regex.sub(r"\s{2,}", " ", lyrics)
insert_query = "INSERT INTO lyrics (src, date_retrieved, artist, song, artistsong, confidence, lyrics)\
insert_query = (
"INSERT INTO lyrics (src, date_retrieved, artist, song, artistsong, confidence, lyrics)\
VALUES(?, ?, ?, ?, ?, ?, ?)"
)
params = (
lyr_result.src,
time.time(),
@ -258,10 +258,8 @@ class Cache:
if artist == "!" and song == "!":
random_search = True
search_query: str = (
"SELECT id, artist, song, lyrics, src, confidence\
search_query: str = "SELECT id, artist, song, lyrics, src, confidence\
FROM lyrics ORDER BY RANDOM() LIMIT 1"
)
logging.info("Searching %s - %s on %s", artist, song, self.label)
@ -320,11 +318,9 @@ class Cache:
self.cache_pre_query
) as _db_cursor:
if not random_search:
search_query: str = (
'SELECT id, artist, song, lyrics, src, confidence FROM lyrics\
search_query: str = 'SELECT id, artist, song, lyrics, src, confidence FROM lyrics\
WHERE editdist3((lower(artist) || " " || lower(song)), (? || " " || ?))\
<= 410 ORDER BY editdist3((lower(artist) || " " || lower(song)), ?) ASC LIMIT 10'
)
search_params: tuple = (
artist.strip(),
song.strip(),

View File

@ -8,9 +8,7 @@ import re
from typing import Optional
from aiohttp import ClientTimeout, ClientSession
from bs4 import BeautifulSoup, ResultSet # type: ignore
from tenacity import (
retry, stop_after_attempt, wait_fixed
)
from tenacity import retry, stop_after_attempt, wait_fixed
import html as htm
from . import private, common, cache, redis_cache
from lyric_search import utils
@ -58,6 +56,7 @@ class Genius:
f"{self.genius_search_url}{search_term}",
timeout=self.timeout,
headers=self.headers,
verify_ssl=False,
) as request:
request.raise_for_status()
text: Optional[str] = await request.text()
@ -109,7 +108,10 @@ class Genius:
scrape_url: str = f"{self.genius_url}{scrape_stub[1:]}"
async with client.get(
scrape_url, timeout=self.timeout, headers=self.headers
scrape_url,
timeout=self.timeout,
headers=self.headers,
verify_ssl=False,
) as scrape_request:
scrape_request.raise_for_status()
scrape_text: Optional[str] = await scrape_request.text()

View File

@ -6,9 +6,7 @@ import traceback
import logging
from typing import Optional, Union
from aiohttp import ClientTimeout, ClientSession
from tenacity import (
retry, stop_after_attempt, wait_fixed
)
from tenacity import retry, stop_after_attempt, wait_fixed
from lyric_search import utils
from lyric_search.constructors import LyricsResult
from . import common, cache, redis_cache