From 11f7eab2eff000476ec96dc4999e7321365264ee Mon Sep 17 00:00:00 2001 From: Archos Date: Mon, 4 May 2026 19:07:32 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20po=C4=8Det=20toot=C5=AF=20t=C3=BDdne/m?= =?UTF-8?q?=C4=9Bs=C3=ADce=20v=20reportu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- daily_top.py | 2 +- weekly_report.py | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/daily_top.py b/daily_top.py index 5d48c8c..84947f4 100644 --- a/daily_top.py +++ b/daily_top.py @@ -112,7 +112,7 @@ def main(): out_path = os.path.join("data", f"{today}.json") with open(out_path, "w", encoding="utf-8") as f: - json.dump({"date": today, "top": top, "tags": tags}, f, ensure_ascii=False, indent=2) + json.dump({"date": today, "total_count": len(timeline), "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ů)") diff --git a/weekly_report.py b/weekly_report.py index a03b0a7..772f194 100644 --- a/weekly_report.py +++ b/weekly_report.py @@ -126,7 +126,7 @@ def format_month_cs(dt): ] return f"{months[dt.month - 1]} {dt.year}" -def build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, instance_info): +def build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, instance_info, total_count=0): stats = {m["key"]: int(m["total"]) for m in measures_data} new_users = stats.get("new_users", 0) active_users = stats.get("active_users", 0) @@ -161,6 +161,7 @@ def build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, inst f"👥 Noví uživatelé: {new_users}{fmt_diff(new_users, 'new_users', long=True)}\n" f"✅ Aktivní uživatelé: {active_users}{fmt_diff(active_users, 'active_users')}\n" f"📝 Interakce: {interactions}{fmt_diff(interactions, 'interactions')}\n" + f"📝 Tooty měsíce: {total_count}\n" f"\n" f"📊 Celkem uživatelů: {user_count}\n" f"🌐 Federovaných instancí: {domain_count}\n" @@ -170,7 +171,7 @@ def build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, inst f"{tooty_sekce}" ) -def build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number): +def build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number, total_count=0): stats = {m["key"]: int(m["total"]) for m in measures_data} new_users = stats.get("new_users", 0) active_users = stats.get("active_users", 0) @@ -200,6 +201,7 @@ def build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number): f"👥 Noví uživatelé: {new_users}\n" f"✅ Aktivní uživatelé: {active_users}\n" f"📝 Interakce: {interactions}\n" + f"📝 Tooty týdne: {total_count}\n" f"\n" f"🔥 Populární hashtagy:\n" f"{hashtags}\n" @@ -247,6 +249,19 @@ def load_tooty_from_data(date_to, days): all_tooty.sort(key=lambda s: s.get("score", 0), reverse=True) return all_tooty[:3] +def load_total_count_from_data(date_to, days): + total = 0 + for i in range(days): + day = (date_to - timedelta(days=i)).strftime("%Y-%m-%d") + path = os.path.join("data", f"{day}.json") + try: + with open(path, encoding="utf-8") as f: + file_data = json.load(f) + total += file_data.get("total_count", 0) + except FileNotFoundError: + pass + return total + def main(): parser = argparse.ArgumentParser(description="Statistiky Mamutovo.cz") parser.add_argument("--dry-run", action="store_true", help="Pouze vypíše toot, neodešle") @@ -299,7 +314,8 @@ def main(): pass top_tooty = load_tooty_from_data(date_to, 30) - toot = build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, instance_info) + total_count = load_total_count_from_data(date_to, 30) + toot = build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, instance_info, total_count) if args.dry_run: print(toot) @@ -344,7 +360,8 @@ def main(): tags = [] top_tooty = load_tooty_from_data(date_to, 7) - toot = build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number) + total_count = load_total_count_from_data(date_to, 7) + toot = build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number, total_count) if args.dry_run: print(toot)