diff --git a/app.py b/app.py index b21047d..ff8f69b 100644 --- a/app.py +++ b/app.py @@ -267,6 +267,26 @@ def send_whatsapp_audio(to: str, media_id: str) -> dict: return r.json() +def _send_email(to: str, subject: str, body: str) -> None: + """Send an email notification using sendmail.""" + import subprocess + from email.message import EmailMessage + msg = EmailMessage() + msg["From"] = "noreply@brettspiel-news.de" + msg["To"] = to + msg["Subject"] = subject + msg.set_content(body) + try: + subprocess.run( + ["/usr/sbin/sendmail", "-t", "-oi"], + input=msg.as_bytes(), + timeout=10, + check=True, + ) + except Exception: + pass # silently ignore email failures + + def download_media(media_id: str) -> tuple[str | None, str | None]: """Download media from WhatsApp. Returns (local_path, mime_type) or (None, None).""" url = f"https://graph.facebook.com/v25.0/{media_id}" @@ -2199,6 +2219,8 @@ def public_frontend(): + + @@ -2262,6 +2284,7 @@ def public_frontend(): sSend.addEventListener('click', async () => { const name = document.getElementById('subName').value.trim(); + const email = document.getElementById('subEmail').value.trim(); const text = document.getElementById('subText').value.trim(); const fileInput = document.getElementById('subPhoto'); const file = fileInput.files[0] || document.getElementById('subVideo').files[0] || document.getElementById('subAudio').files[0] || document.getElementById('subGallery').files[0]; @@ -2280,6 +2303,7 @@ def public_frontend(): const formData = new FormData(); if (name) formData.append('name', name); + if (email) formData.append('email', email); if (text) formData.append('text', text); if (file) formData.append('media', file); if (halle) formData.append('halle', halle); @@ -2301,6 +2325,7 @@ def public_frontend(): + ''; sStatus.style.color = '#20228a'; document.getElementById('subName').value = ''; + document.getElementById('subEmail').value = ''; document.getElementById('subText').value = ''; fileInput.value = ''; document.getElementById('subVideo').value = ''; @@ -3007,6 +3032,7 @@ def api_submit(): text = (request.form.get('text') or '').strip()[:5000] halle = (request.form.get('halle') or '').strip()[:20] spiel_titel = (request.form.get('spiel_titel') or '').strip()[:200] + email = (request.form.get('email') or '').strip()[:200] # Require at least text or a file file = request.files.get('media') @@ -3087,9 +3113,9 @@ def api_submit(): db.execute( """INSERT INTO submissions - (channel, sender_id, sender_name, type, content, media_path, status, halle, category, spiel_titel) - VALUES (?, ?, ?, ?, ?, ?, 'new', ?, ?, ?)""", - ('web', sender_id, sender_name, msg_type, text or None, media_path, halle_valid, category, spiel_titel or None), + (channel, sender_id, sender_name, type, content, media_path, status, halle, category, spiel_titel, email) + VALUES (?, ?, ?, ?, ?, ?, 'new', ?, ?, ?, ?)""", + ('web', sender_id, sender_name, msg_type, text or None, media_path, halle_valid, category, spiel_titel or None, email or None), ) db.commit() sub_id = db.execute("SELECT last_insert_rowid()").fetchone()[0] @@ -3186,6 +3212,25 @@ def public_detail(sub_id: int): content = (row["summary"] or row["content"] or "").strip() + # Comments + comment_rows = db.execute( + "SELECT author_name, content, created_at FROM comments WHERE submission_id = ? ORDER BY created_at ASC", + (sub_id,), + ).fetchall() + comments_html = "" + for c in comment_rows: + c_author = (c["author_name"] or "Anonym").strip() + c_date = c["created_at"] or "" + try: + cd = datetime.strptime(c_date, "%Y-%m-%d %H:%M:%S") + c_date = cd.strftime("%d.%m.%y %H:%M") + except Exception: + pass + comments_html += f"""
{c["content"]}
+