feat: počet tootů týdne/měsíce v reportu

This commit is contained in:
2026-05-04 19:07:32 +02:00
parent 1a300680e3
commit 11f7eab2ef
2 changed files with 22 additions and 5 deletions
+1 -1
View File
@@ -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ů)")
+21 -4
View File
@@ -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)