59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Täglicher Feed-Report — läuft via Cron um 22:00."""
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
import requests
|
|
from core import config
|
|
|
|
def main():
|
|
cfg = config.parse_config()
|
|
ct_109 = config.get_container(cfg, vmid=109)
|
|
if not ct_109:
|
|
return
|
|
|
|
url = f"http://{ct_109.tailscale_ip}:8080/api/feed-stats"
|
|
try:
|
|
r = requests.get(url, timeout=10)
|
|
stats = r.json()
|
|
except Exception as e:
|
|
print(f"RSS Manager nicht erreichbar: {e}")
|
|
return
|
|
|
|
today = stats["today"]
|
|
yesterday = stats["yesterday"]
|
|
feeds = stats["feeds"]
|
|
lines = [f"📊 Täglicher Feed-Report ({stats['date']})", f"Artikel heute: {today} (gestern: {yesterday})", ""]
|
|
active = [f for f in feeds if f["posts_today"] > 0]
|
|
if active:
|
|
lines.append("📰 Aktive Feeds:")
|
|
for f in active:
|
|
lines.append(f" {f['name']}: {f['posts_today']} ({f['schedule']})")
|
|
silent = [f for f in feeds if f["posts_today"] == 0]
|
|
if silent:
|
|
lines.append("")
|
|
lines.append("😴 Keine Artikel heute:")
|
|
for f in silent:
|
|
yd = f"(gestern: {f['posts_yesterday']})" if f["posts_yesterday"] > 0 else "(auch gestern 0)"
|
|
lines.append(f" {f['name']} {yd}")
|
|
errors = [f for f in feeds if f.get("error_count", 0) > 0]
|
|
if errors:
|
|
lines.append("")
|
|
lines.append("⚠️ Fehler:")
|
|
for f in errors:
|
|
lines.append(f" {f['name']}: {f['error_count']}x — {f['last_error']}")
|
|
|
|
msg = "\n".join(lines)
|
|
token = cfg.raw.get("TG_HAUSMEISTER_TOKEN", "")
|
|
chat_id = cfg.raw.get("TG_CHAT_ID", "")
|
|
if token and chat_id:
|
|
requests.post(
|
|
f"https://api.telegram.org/bot{token}/sendMessage",
|
|
data={"chat_id": chat_id, "text": msg},
|
|
timeout=10,
|
|
)
|
|
print("Report gesendet")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|