Fabrik als Provider Korrigiert
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
from app.config import settings
|
||||
from app.models import RegionScope, WatchType
|
||||
from app.providers.utils import normalize_search_text
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EventimProvider:
|
||||
@@ -46,12 +51,31 @@ class EventimProvider:
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
if response.status_code in {403, 429}:
|
||||
logger.warning(
|
||||
"Eventim API blocked request with status %s for term '%s'.",
|
||||
response.status_code,
|
||||
term,
|
||||
)
|
||||
setattr(self, "last_status", "blocked")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
f"Eventim API blocked request with status {response.status_code} for term '{term}'.",
|
||||
)
|
||||
return []
|
||||
response.raise_for_status()
|
||||
payload = response.json()
|
||||
products = payload.get("products") or []
|
||||
setattr(self, "last_status", "ok")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
f"Eventim returned {len(products)} raw products for term '{term}'.",
|
||||
)
|
||||
|
||||
results: list[dict] = []
|
||||
normalized_term = term.casefold()
|
||||
normalized_term = normalize_search_text(term)
|
||||
|
||||
for product in products:
|
||||
title = product.get("name") or ""
|
||||
@@ -59,10 +83,10 @@ class EventimProvider:
|
||||
attraction_names = [entry.get("name", "") for entry in attractions]
|
||||
|
||||
if watch_type == WatchType.artist:
|
||||
haystack = " ".join(attraction_names + [title]).casefold()
|
||||
haystack = normalize_search_text(" ".join(attraction_names + [title]))
|
||||
if normalized_term not in haystack:
|
||||
continue
|
||||
elif normalized_term not in title.casefold():
|
||||
elif normalized_term not in normalize_search_text(title):
|
||||
continue
|
||||
|
||||
live_data = product.get("typeAttributes", {}).get("liveEntertainment", {})
|
||||
|
||||
Reference in New Issue
Block a user