Social: Trainingstipp-Generator, Übungen in DB, 3 Stil-Varianten

- training_exercises Tabelle mit 13 Übungen aus App-Bibliothek
- POST /social/training-tip: Stil-Varianten tutorial/community/aspirational
- exercise_id in social_content für Wiederholungs-Tracking
- Admin-Stats: Social-Media-Sektion mit Status-Übersicht + letzte 10 Posts
- SW by-v349, APP_VER 336
This commit is contained in:
rene 2026-04-24 20:13:22 +02:00
parent ca0ce79815
commit 1cb0c2df77
8 changed files with 1497 additions and 337 deletions

View file

@ -163,6 +163,40 @@ async def stats(user=Depends(require_mod)):
except Exception:
ki_today = ki_month = ki_users_today = 0
# Social Media Tracking
try:
social_total = conn.execute("SELECT COUNT(*) FROM social_content").fetchone()[0]
social_published = conn.execute(
"SELECT COUNT(*) FROM social_content WHERE status='published'"
).fetchone()[0]
social_scheduled = conn.execute(
"SELECT COUNT(*) FROM social_content WHERE status='scheduled'"
).fetchone()[0]
social_ideas = conn.execute(
"SELECT COUNT(*) FROM social_content WHERE status='idea'"
).fetchone()[0]
social_this_week = conn.execute(
"SELECT COUNT(*) FROM social_content WHERE status='published' "
"AND published_at >= datetime('now', '-7 days')"
).fetchone()[0]
social_by_cat = {
row[0]: row[1] for row in conn.execute(
"SELECT category, COUNT(*) FROM social_content "
"WHERE category IS NOT NULL GROUP BY category ORDER BY 2 DESC"
).fetchall()
}
social_recent = [dict(r) for r in conn.execute(
"""SELECT topic, status, platform, format, created_at,
published_at, category, ai_score
FROM social_content
ORDER BY created_at DESC LIMIT 10"""
).fetchall()]
except Exception:
social_total = social_published = social_scheduled = 0
social_ideas = social_this_week = 0
social_by_cat = {}
social_recent = []
return {
"users_total": users_total,
"users_today": users_today,
@ -183,6 +217,13 @@ async def stats(user=Depends(require_mod)):
"ki_today": ki_today,
"ki_month": ki_month,
"ki_users_today": ki_users_today,
"social_total": social_total,
"social_published": social_published,
"social_scheduled": social_scheduled,
"social_ideas": social_ideas,
"social_this_week": social_this_week,
"social_by_cat": social_by_cat,
"social_recent": social_recent,
}