This commit is contained in:
bskjon 2024-04-15 01:03:16 +02:00
parent 353217bd3f
commit b407159f22
2 changed files with 9 additions and 5 deletions

View File

@ -8,7 +8,7 @@ from .mal import metadata as MalMetadata
from fuzzywuzzy import fuzz from fuzzywuzzy import fuzz
from unidecode import unidecode from unidecode import unidecode
import json import json
import re
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -28,6 +28,9 @@ class UseSource():
def __init__(self, title, eventId) -> None: def __init__(self, title, eventId) -> None:
self.title = title self.title = title
def stripped(input_string):
return re.sub(r'[^a-zA-Z0-9]', '', input_string)
def __perform_search(self, title)-> List[WeightedData]: def __perform_search(self, title)-> List[WeightedData]:
anii = AniiMetadata(title).lookup() anii = AniiMetadata(title).lookup()
imdb = ImdbMetadata(title).lookup() imdb = ImdbMetadata(title).lookup()
@ -38,6 +41,7 @@ class UseSource():
result.append(WeightedData(anii, 2)) result.append(WeightedData(anii, 2))
if (imdb is not None) and (imdb.status == "COMPLETED" and imdb.data is not None): if (imdb is not None) and (imdb.status == "COMPLETED" and imdb.data is not None):
imdb_weight = 1 imdb_weight = 1
#if (imdb.data.title == title or unidecode(self.stripped(imdb.data.title)) == unidecode(self.stripped(title))): To use after test
if (imdb.data.title == title or unidecode(imdb.data.title) == unidecode(title)): if (imdb.data.title == title or unidecode(imdb.data.title) == unidecode(title)):
imdb_weight = 10 imdb_weight = 10
result.append(WeightedData(imdb, imdb_weight)) result.append(WeightedData(imdb, imdb_weight))
@ -49,9 +53,9 @@ class UseSource():
"""""" """"""
result: List[WeightedData] = [] result: List[WeightedData] = []
for wd in weightData: for wd in weightData:
highScore = fuzz.ratio(title.lower(), wd.result.data.title.lower()) highScore = fuzz.ratio(self.stripped(title.lower()), self.stripped(wd.result.data.title.lower()))
for name in wd.result.data.altTitle: for name in wd.result.data.altTitle:
altScore = fuzz.ratio(title.lower(), name.lower()) altScore = fuzz.ratio(self.stripped(title.lower()), self.stripped(name.lower()))
if (altScore > highScore): if (altScore > highScore):
highScore = altScore highScore = altScore
givenScore = highScore * (wd.weight / 10) givenScore = highScore * (wd.weight / 10)
@ -71,7 +75,7 @@ class UseSource():
f.write(jsr) f.write(jsr)
except: except:
logger.info("Couldn't dump log..") logger.info("Couldn't dump log..")
logger.info(jsr)
try: try:
titles: List[str] = [] titles: List[str] = []

View File

@ -14,7 +14,7 @@ RUN pip3 install -r ./requirements.txt
# Kopier resten av prosjektfilene # Kopier resten av prosjektfilene
COPY ./apps/${MODULE_NAME}/ . COPY ./apps/${MODULE_NAME}/ .
RUN mkdir -p /apps/logs RUN mkdir -p /app/logs
# Start applikasjonen # Start applikasjonen
CMD ["python3", "-u", "app.py"] CMD ["python3", "-u", "app.py"]