Add Frigate Daily Report: Telegram integration, daily 20:30 CET summary
This commit is contained in:
parent
0c4086f243
commit
400740b541
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
cd /home/marc/bot-deploy
|
||||
|
||||
# Generate report
|
||||
REPORT=$(python3 src/frigate_report.py)
|
||||
|
||||
# Send to Telegram via Hermes
|
||||
echo "$REPORT" | hermes send-message telegram --message-file /dev/stdin || true
|
||||
|
||||
# Also save to log
|
||||
echo "[$(date)]" >> /tmp/frigate-reports.log
|
||||
echo "$REPORT" >> /tmp/frigate-reports.log
|
||||
echo "" >> /tmp/frigate-reports.log
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Frigate Daily Report Generator
|
||||
Sends to Telegram every evening at 20:30 CET
|
||||
"""
|
||||
import os, json, requests
|
||||
from datetime import datetime, timedelta
|
||||
from collections import defaultdict
|
||||
|
||||
FRIGATE_URL = "http://localhost:5000"
|
||||
|
||||
def get_frigate_events():
|
||||
"""Get events from last 24 hours"""
|
||||
try:
|
||||
resp = requests.get(f"{FRIGATE_URL}/api/events", timeout=5)
|
||||
events = resp.json()
|
||||
|
||||
# Filter for last 24h
|
||||
now = datetime.now().timestamp()
|
||||
yesterday = now - (24 * 3600)
|
||||
|
||||
recent = [e for e in events if e.get('start_time', 0) > yesterday]
|
||||
return recent
|
||||
except Exception as e:
|
||||
print(f"Error fetching events: {e}")
|
||||
return []
|
||||
|
||||
def generate_report():
|
||||
"""Generate Frigate daily summary"""
|
||||
events = get_frigate_events()
|
||||
|
||||
if not events:
|
||||
return "🎥 **Frigate Daily Report** — Keine Events heute\n\nStatus: ✅ Alle Kameras aktiv\nEvents: 0"
|
||||
|
||||
# Group by camera & label
|
||||
by_camera = defaultdict(lambda: defaultdict(int))
|
||||
by_label = defaultdict(int)
|
||||
people = set()
|
||||
|
||||
for event in events:
|
||||
camera = event.get('camera', 'Unknown')
|
||||
label = event.get('label', 'Unknown')
|
||||
sub_label = event.get('sub_label', None)
|
||||
|
||||
by_camera[camera][label] += 1
|
||||
by_label[label] += 1
|
||||
|
||||
if label == 'person' and sub_label:
|
||||
people.add(sub_label)
|
||||
|
||||
# Format report
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M CET')
|
||||
report = f"""🎥 **Frigate Daily Report** — {timestamp}
|
||||
|
||||
📊 **ZUSAMMENFASSUNG**
|
||||
• Gesamt Events: {len(events)}
|
||||
• Detektierte Personen: {len(people)}
|
||||
• Kameras aktiv: {len(by_camera)}
|
||||
|
||||
👥 **Erkannte Personen**
|
||||
"""
|
||||
|
||||
for person in sorted(people):
|
||||
report += f" • {person}\n"
|
||||
|
||||
report += f"\n📹 **Nach Kamera**\n"
|
||||
|
||||
for camera in sorted(by_camera.keys()):
|
||||
events_count = sum(by_camera[camera].values())
|
||||
labels = ", ".join(by_camera[camera].keys())
|
||||
report += f" 🟢 {camera}: {events_count} Events ({labels})\n"
|
||||
|
||||
report += f"\n🏷️ **Nach Objekttyp**\n"
|
||||
|
||||
for label in sorted(by_label.keys()):
|
||||
count = by_label[label]
|
||||
report += f" • {label.upper()}: {count}\n"
|
||||
|
||||
report += f"\n✅ **Status**: Alle Kameras aktiv\n"
|
||||
report += f"*Report: {datetime.now().strftime('%H:%M:%S UTC')}*"
|
||||
|
||||
return report
|
||||
|
||||
if __name__ == "__main__":
|
||||
report = generate_report()
|
||||
print(report)
|
||||
Loading…
Reference in New Issue