globe-feed: Vollstaendige Artikel-Details pro Standort
Dieser Commit ist enthalten in:
@@ -269,7 +269,7 @@ async def get_globe_feed(
|
|||||||
inc_ids = [i["id"] for i in incidents]
|
inc_ids = [i["id"] for i in incidents]
|
||||||
ids_sql = ",".join(str(i) for i in inc_ids)
|
ids_sql = ",".join(str(i) for i in inc_ids)
|
||||||
|
|
||||||
# Locations mit Artikel-Headlines
|
# Locations mit vollstaendigen Artikel-Details
|
||||||
cursor = await db.execute(
|
cursor = await db.execute(
|
||||||
f"""SELECT
|
f"""SELECT
|
||||||
al.location_name_normalized as name,
|
al.location_name_normalized as name,
|
||||||
@@ -278,37 +278,69 @@ async def get_globe_feed(
|
|||||||
al.country_code,
|
al.country_code,
|
||||||
al.category,
|
al.category,
|
||||||
al.incident_id,
|
al.incident_id,
|
||||||
COUNT(*) as article_count,
|
al.article_id
|
||||||
MAX(al.confidence) as confidence,
|
|
||||||
GROUP_CONCAT(DISTINCT a.headline_de) as headlines
|
|
||||||
FROM article_locations al
|
FROM article_locations al
|
||||||
LEFT JOIN articles a ON al.article_id = a.id
|
|
||||||
WHERE al.incident_id IN ({ids_sql})
|
WHERE al.incident_id IN ({ids_sql})
|
||||||
GROUP BY al.location_name_normalized, al.incident_id
|
ORDER BY al.location_name_normalized"""
|
||||||
ORDER BY article_count DESC
|
|
||||||
LIMIT 500"""
|
|
||||||
)
|
)
|
||||||
locations = [dict(r) for r in await cursor.fetchall()]
|
loc_rows = [dict(r) for r in await cursor.fetchall()]
|
||||||
|
|
||||||
|
# Artikel-IDs sammeln
|
||||||
|
all_article_ids = list(set(r["article_id"] for r in loc_rows if r.get("article_id")))
|
||||||
|
|
||||||
|
# Artikel laden
|
||||||
|
articles_map = {{}}
|
||||||
|
if all_article_ids:
|
||||||
|
aids_sql = ",".join(str(a) for a in all_article_ids[:1000])
|
||||||
|
cursor = await db.execute(
|
||||||
|
f"""SELECT id, headline_de, headline, source, source_url, content_de,
|
||||||
|
published_at, collected_at
|
||||||
|
FROM articles WHERE id IN ({{aids_sql}})"""
|
||||||
|
)
|
||||||
|
for a in await cursor.fetchall():
|
||||||
|
a = dict(a)
|
||||||
|
articles_map[a["id"]] = a
|
||||||
|
|
||||||
|
# Nach Ort gruppieren
|
||||||
|
from collections import defaultdict
|
||||||
|
loc_groups = defaultdict(lambda: {{"articles": [], "lat": 0, "lon": 0, "country": "", "category": "", "incident_id": 0}})
|
||||||
|
for r in loc_rows:
|
||||||
|
key = r["name"] or "unknown"
|
||||||
|
g = loc_groups[key]
|
||||||
|
g["lat"] = r["lat"]
|
||||||
|
g["lon"] = r["lon"]
|
||||||
|
g["country"] = r["country_code"]
|
||||||
|
g["category"] = r["category"]
|
||||||
|
g["incident_id"] = r["incident_id"]
|
||||||
|
if r.get("article_id") and r["article_id"] in articles_map:
|
||||||
|
art = articles_map[r["article_id"]]
|
||||||
|
if art not in g["articles"]:
|
||||||
|
g["articles"].append(art)
|
||||||
|
|
||||||
# Als GeoJSON
|
# Als GeoJSON
|
||||||
features = []
|
features = []
|
||||||
for loc in locations:
|
for name, g in list(loc_groups.items())[:500]:
|
||||||
inc = next((i for i in incidents if i["id"] == loc["incident_id"]), None)
|
inc = next((i for i in incidents if i["id"] == g["incident_id"]), None)
|
||||||
headlines = (loc.get("headlines") or "").split(",")[:5]
|
art_list = g["articles"][:5]
|
||||||
features.append({
|
features.append({{
|
||||||
"type": "Feature",
|
"type": "Feature",
|
||||||
"geometry": {"type": "Point", "coordinates": [loc["lon"], loc["lat"]]},
|
"geometry": {{"type": "Point", "coordinates": [g["lon"], g["lat"]]}},
|
||||||
"properties": {
|
"properties": {{
|
||||||
"name": loc["name"],
|
"name": name,
|
||||||
"country": loc["country_code"],
|
"country": g["country"],
|
||||||
"category": loc["category"],
|
"category": g["category"],
|
||||||
"article_count": loc["article_count"],
|
"article_count": len(g["articles"]),
|
||||||
"confidence": loc["confidence"],
|
"incident_id": g["incident_id"],
|
||||||
"incident_id": loc["incident_id"],
|
|
||||||
"incident_title": inc["title"] if inc else "",
|
"incident_title": inc["title"] if inc else "",
|
||||||
"headlines": headlines,
|
"articles": [{{
|
||||||
},
|
"headline": a.get("headline_de") or a.get("headline", ""),
|
||||||
})
|
"source": a.get("source", ""),
|
||||||
|
"url": a.get("source_url", ""),
|
||||||
|
"summary": (a.get("content_de") or "")[:300],
|
||||||
|
"date": a.get("published_at") or a.get("collected_at", ""),
|
||||||
|
}} for a in art_list],
|
||||||
|
}},
|
||||||
|
}})
|
||||||
|
|
||||||
# Incident-Summaries
|
# Incident-Summaries
|
||||||
inc_summaries = []
|
inc_summaries = []
|
||||||
|
|||||||
In neuem Issue referenzieren
Einen Benutzer sperren