top_articles pro Location in Lagebild-API ergänzen

_build_lagebild_response() liefert jetzt Top-3-Artikel (neueste)
pro Location für Karten-Popups mit klickbaren Quellen-Links.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dieser Commit ist enthalten in:
claude-dev
2026-04-11 11:55:35 +00:00
Ursprung 68c4e2a9c9
Commit 5a56024501

Datei anzeigen

@@ -142,6 +142,30 @@ async def _build_lagebild_response(db, incident_ids: list, primary_id: int) -> d
)
locations = [dict(r) for r in await cursor.fetchall()]
# Top-3-Artikel pro Location (neueste zuerst)
cursor = await db.execute(
f"""SELECT al.location_name_normalized as loc_name,
a.headline_de, a.headline, a.source, a.source_url
FROM article_locations al
JOIN articles a ON a.id = al.article_id
WHERE al.incident_id IN ({ids})
ORDER BY a.published_at DESC"""
)
loc_articles = {}
for r in await cursor.fetchall():
r = dict(r)
name = r["loc_name"]
if name not in loc_articles:
loc_articles[name] = []
if len(loc_articles[name]) < 3:
loc_articles[name].append({
"headline": r["headline_de"] or r["headline"] or "",
"source": r["source"] or "",
"url": r["source_url"] or "",
})
for loc in locations:
loc["top_articles"] = loc_articles.get(loc["name"], [])
return {
"generated_at": datetime.now(TIMEZONE).isoformat(),
"incident": {