feat: top přispěvatel, nový účet, milník v reportu

This commit is contained in:
2026-05-04 19:31:00 +02:00
parent 11f7eab2ef
commit a22d761211
2 changed files with 99 additions and 8 deletions
+27 -2
View File
@@ -66,12 +66,13 @@ def fetch_daily_timeline(base_url, token):
def main():
env = {**load_env(), **os.environ}
for var in ("NOVINKY_TOKEN", "INSTANCE_URL"):
for var in ("NOVINKY_TOKEN", "INSTANCE_URL", "STATS_TOKEN"):
if not env.get(var):
print(f"Chybí proměnná prostředí: {var}", file=sys.stderr)
sys.exit(1)
token = env["NOVINKY_TOKEN"]
stats_token = env["STATS_TOKEN"]
base_url = env["INSTANCE_URL"].rstrip("/")
try:
@@ -107,12 +108,36 @@ def main():
top = candidates[:3]
tags = [t for t, _ in sorted(tag_counts.items(), key=lambda x: x[1], reverse=True)[:5]]
authors_count = {}
for c in candidates:
authors_count[c["acct"]] = authors_count.get(c["acct"], 0) + 1
newest_account = None
try:
accounts = api_get(
f"{base_url}/api/v1/admin/accounts?order=newest&limit=1", stats_token
)
if accounts and accounts[0].get("account", {}).get("discoverable"):
newest_account = {
"acct": accounts[0]["account"]["acct"],
"created_at": accounts[0]["created_at"],
}
except Exception:
pass
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
os.makedirs("data", exist_ok=True)
out_path = os.path.join("data", f"{today}.json")
with open(out_path, "w", encoding="utf-8") as f:
json.dump({"date": today, "total_count": len(timeline), "top": top, "tags": tags}, f, ensure_ascii=False, indent=2)
json.dump({
"date": today,
"total_count": len(timeline),
"authors_count": authors_count,
"newest_account": newest_account,
"top": top,
"tags": tags,
}, f, ensure_ascii=False, indent=2)
print(f"Uloženo: {out_path} ({len(timeline)} tootů načteno, {len(top)} top, {len(tags)} hashtagů)")