Fabrik als Provider Korrigiert
This commit is contained in:
@@ -5,6 +5,7 @@ import requests
|
||||
|
||||
from app.config import settings
|
||||
from app.models import RegionScope, WatchType
|
||||
from app.providers.utils import normalize_search_text
|
||||
|
||||
|
||||
class BandsintownProvider:
|
||||
@@ -21,9 +22,21 @@ class BandsintownProvider:
|
||||
region_scope: RegionScope,
|
||||
) -> list[dict]:
|
||||
if not self.is_configured():
|
||||
setattr(self, "last_status", "ok")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
"Bandsintown ist nicht konfiguriert. Bitte eine gueltige BANDSINTOWN_APP_ID setzen.",
|
||||
)
|
||||
return []
|
||||
|
||||
if watch_type != WatchType.artist:
|
||||
setattr(self, "last_status", "ok")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
f"Bandsintown skipped non-artist watch item '{term}'.",
|
||||
)
|
||||
return []
|
||||
|
||||
artist_name = quote(term, safe="")
|
||||
@@ -34,15 +47,46 @@ class BandsintownProvider:
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
if response.status_code in {401, 403, 429}:
|
||||
setattr(self, "last_status", "blocked")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
(
|
||||
f"Bandsintown rejected app_id for '{term}' "
|
||||
f"with status {response.status_code}."
|
||||
),
|
||||
)
|
||||
return []
|
||||
|
||||
if response.status_code == 404:
|
||||
setattr(self, "last_status", "ok")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
f"Bandsintown found no artist match for '{term}'.",
|
||||
)
|
||||
return []
|
||||
|
||||
response.raise_for_status()
|
||||
payload = response.json()
|
||||
if not isinstance(payload, list):
|
||||
setattr(self, "last_status", "error")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
f"Bandsintown returned an unexpected payload for '{term}'.",
|
||||
)
|
||||
return []
|
||||
setattr(self, "last_status", "ok")
|
||||
setattr(
|
||||
self,
|
||||
"last_message",
|
||||
f"Bandsintown returned {len(payload)} raw events for term '{term}'.",
|
||||
)
|
||||
|
||||
results: list[dict] = []
|
||||
normalized_term = normalize_search_text(term)
|
||||
for item in payload:
|
||||
venue = item.get("venue") or {}
|
||||
city = venue.get("city")
|
||||
@@ -66,10 +110,16 @@ class BandsintownProvider:
|
||||
offers = item.get("offers") or []
|
||||
ticket_url = next((offer.get("url") for offer in offers if offer.get("url")), None)
|
||||
|
||||
title = item.get("title") or f"{term} live"
|
||||
artist_name = item.get("artist", {}).get("name", term)
|
||||
haystack = normalize_search_text(f"{artist_name} {title}")
|
||||
if normalized_term not in haystack:
|
||||
continue
|
||||
|
||||
results.append(
|
||||
{
|
||||
"external_id": str(item.get("id")),
|
||||
"title": item.get("title") or f"{term} live",
|
||||
"title": title,
|
||||
"matched_term": term,
|
||||
"venue_name": venue.get("name"),
|
||||
"city": city,
|
||||
@@ -82,4 +132,3 @@ class BandsintownProvider:
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
Reference in New Issue
Block a user