Fix: Alle Timestamps einheitlich auf Europe/Berlin Zeitzone
Inkonsistenz behoben: Manche Timestamps wurden in UTC, andere in Berlin-Zeit gespeichert. Das fuehrte zu Fehlern beim Auto-Refresh und Faktencheck, da Zeitvergleiche falsche Ergebnisse lieferten. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dieser Commit ist enthalten in:
@@ -5,7 +5,8 @@ from models import IncidentCreate, IncidentUpdate, IncidentResponse, Subscriptio
|
||||
from auth import get_current_user
|
||||
from middleware.license_check import require_writable_license
|
||||
from database import db_dependency, get_db
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from config import TIMEZONE
|
||||
import asyncio
|
||||
import aiosqlite
|
||||
import json
|
||||
@@ -101,7 +102,7 @@ async def create_incident(
|
||||
):
|
||||
"""Neue Lage anlegen."""
|
||||
tenant_id = current_user.get("tenant_id")
|
||||
now = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
|
||||
now = datetime.now(TIMEZONE).strftime('%Y-%m-%d %H:%M:%S')
|
||||
cursor = await db.execute(
|
||||
"""INSERT INTO incidents (title, description, type, refresh_mode, refresh_interval,
|
||||
retention_days, international_sources, visibility,
|
||||
@@ -183,7 +184,7 @@ async def update_incident(
|
||||
if not updates:
|
||||
return await _enrich_incident(db, row)
|
||||
|
||||
updates["updated_at"] = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
|
||||
updates["updated_at"] = datetime.now(TIMEZONE).strftime('%Y-%m-%d %H:%M:%S')
|
||||
set_clause = ", ".join(f"{k} = ?" for k in updates)
|
||||
values = list(updates.values()) + [incident_id]
|
||||
|
||||
@@ -286,7 +287,7 @@ async def get_locations(
|
||||
await _check_incident_access(db, incident_id, current_user["id"], tenant_id)
|
||||
cursor = await db.execute(
|
||||
"""SELECT al.location_name, al.location_name_normalized, al.country_code,
|
||||
al.latitude, al.longitude, al.confidence,
|
||||
al.latitude, al.longitude, al.confidence, al.category,
|
||||
a.id as article_id, a.headline, a.headline_de, a.source, a.source_url
|
||||
FROM article_locations al
|
||||
JOIN articles a ON a.id = al.article_id
|
||||
@@ -310,8 +311,11 @@ async def get_locations(
|
||||
"confidence": row["confidence"],
|
||||
"article_count": 0,
|
||||
"articles": [],
|
||||
"categories": {},
|
||||
}
|
||||
loc_map[key]["article_count"] += 1
|
||||
cat = row["category"] or "mentioned"
|
||||
loc_map[key]["categories"][cat] = loc_map[key]["categories"].get(cat, 0) + 1
|
||||
# Maximal 10 Artikel pro Ort mitliefern
|
||||
if len(loc_map[key]["articles"]) < 10:
|
||||
loc_map[key]["articles"].append({
|
||||
@@ -321,7 +325,18 @@ async def get_locations(
|
||||
"source_url": row["source_url"],
|
||||
})
|
||||
|
||||
return list(loc_map.values())
|
||||
# Dominanteste Kategorie pro Ort bestimmen (Prioritaet: target > retaliation > actor > mentioned)
|
||||
priority = {"target": 4, "retaliation": 3, "actor": 2, "mentioned": 1}
|
||||
result = []
|
||||
for loc in loc_map.values():
|
||||
cats = loc.pop("categories")
|
||||
if cats:
|
||||
best_cat = max(cats, key=lambda c: (priority.get(c, 0), cats[c]))
|
||||
else:
|
||||
best_cat = "mentioned"
|
||||
loc["category"] = best_cat
|
||||
result.append(loc)
|
||||
return result
|
||||
|
||||
|
||||
# Geoparse-Status pro Incident (in-memory)
|
||||
@@ -364,11 +379,11 @@ async def _run_geoparse_background(incident_id: int, tenant_id: int | None):
|
||||
await db.execute(
|
||||
"""INSERT INTO article_locations
|
||||
(article_id, incident_id, location_name, location_name_normalized,
|
||||
country_code, latitude, longitude, confidence, source_text, tenant_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
country_code, latitude, longitude, confidence, source_text, tenant_id, category)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(art_id, incident_id, loc["location_name"], loc["location_name_normalized"],
|
||||
loc["country_code"], loc["lat"], loc["lon"], loc["confidence"],
|
||||
loc.get("source_text", ""), tenant_id),
|
||||
loc.get("source_text", ""), tenant_id, loc.get("category", "mentioned")),
|
||||
)
|
||||
geo_count += 1
|
||||
await db.commit()
|
||||
@@ -652,7 +667,7 @@ def _build_markdown_export(
|
||||
lines.append(snap_summary)
|
||||
lines.append("")
|
||||
|
||||
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
|
||||
now = datetime.now(TIMEZONE).strftime("%Y-%m-%d %H:%M UTC")
|
||||
lines.append("---")
|
||||
lines.append(f"*Exportiert am {now} aus AegisSight Monitor*")
|
||||
return "\n".join(lines)
|
||||
@@ -663,7 +678,7 @@ def _build_json_export(
|
||||
snapshots: list, scope: str, creator: str
|
||||
) -> dict:
|
||||
"""Strukturiertes JSON fuer Export."""
|
||||
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
now = datetime.now(TIMEZONE).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
sources = []
|
||||
sources_json = incident.get("sources_json")
|
||||
@@ -772,7 +787,7 @@ async def export_incident(
|
||||
snapshots = [dict(r) for r in await cursor.fetchall()]
|
||||
|
||||
# Dateiname
|
||||
date_str = datetime.now(timezone.utc).strftime("%Y%m%d")
|
||||
date_str = datetime.now(TIMEZONE).strftime("%Y%m%d")
|
||||
slug = _slugify(incident["title"])
|
||||
scope_suffix = "_vollexport" if scope == "full" else ""
|
||||
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren