From 4da5e6790ce6ee0721165ea76ca62d5f7faca35f Mon Sep 17 00:00:00 2001 From: Archos Date: Mon, 15 Jun 2026 19:06:22 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20t=C3=BDdenn=C3=AD=20porovn=C3=A1n=C3=AD?= =?UTF-8?q?=20statistik=20s=20minul=C3=BDm=20t=C3=BDdnem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weekly_report.py | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/weekly_report.py b/weekly_report.py index ba39284..e3c0200 100644 --- a/weekly_report.py +++ b/weekly_report.py @@ -194,12 +194,20 @@ def build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, inst ) def build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number, - total_count=0, top_author=None, newest_account=None, user_count=0, top_links=None): + total_count=0, top_author=None, newest_account=None, user_count=0, top_links=None, + prev_stats=None): 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) interactions = stats.get("interactions", 0) + def fmt_diff(current, key): + if not prev_stats or key not in prev_stats: + return "" + d = current - prev_stats[key] + sign = "+" if d >= 0 else "" + return f" ({sign}{d})" + hashtags = " ".join(f"#{t['name']}" for t in tags[:3]) if tags else "(žádné)" tip = TIPS[week_number % len(TIPS)] @@ -235,9 +243,9 @@ def build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number, f"🐘 Týdenní přehled Mamutovo.cz\n" f"📅 {date_from_str} – {date_to_str} {year}\n" f"\n" - f"👥 Noví uživatelé: {new_users}\n" - f"✅ Aktivní uživatelé: {active_users}\n" - f"📝 Interakce: {interactions}\n" + f"👥 Noví uživatelé: {new_users}{fmt_diff(new_users, 'new_users')}\n" + f"✅ Aktivní uživatelé: {active_users}{fmt_diff(active_users, 'active_users')}\n" + f"📝 Interakce: {interactions}{fmt_diff(interactions, 'interactions')}\n" f"📝 Tooty týdne: {total_count}\n" f"\n" f"🔥 Populární hashtagy:\n" @@ -461,6 +469,14 @@ def main(): instance_info = {} user_count = instance_info.get("stats", {}).get("user_count", 0) + weekly_stats_path = os.path.join("data", "weekly_stats.json") + prev_stats = None + try: + with open(weekly_stats_path, encoding="utf-8") as f: + prev_stats = json.load(f) + except FileNotFoundError: + pass + top_tooty = load_tooty_from_data(date_to, 7) total_count = load_total_count_from_data(date_to, 7) top_author = load_top_author_from_data(date_to, 7) @@ -468,7 +484,7 @@ def main(): top_links = load_top_links_from_data(date_to, 7) toot = build_toot( measures_data, tags, top_tooty, date_from, date_to, week_number, - total_count, top_author, newest_account, user_count, top_links, + total_count, top_author, newest_account, user_count, top_links, prev_stats, ) if args.dry_run: @@ -485,6 +501,17 @@ def main(): except Exception: sys.exit(1) + cur_stats = {m["key"]: int(m["total"]) for m in measures_data} + os.makedirs("data", exist_ok=True) + with open(weekly_stats_path, "w", encoding="utf-8") as f: + json.dump({ + "date": date_to.strftime("%Y-%m-%d"), + "new_users": cur_stats.get("new_users", 0), + "active_users": cur_stats.get("active_users", 0), + "interactions": cur_stats.get("interactions", 0), + }, f, ensure_ascii=False, indent=2) + print("Týdenní statistiky uloženy.") + cutoff = date_to - timedelta(days=60) data_dir = "data" if os.path.isdir(data_dir):