feat: počítání sdílených médií v týdenním i měsíčním přehledu

This commit is contained in:
2026-06-15 19:11:10 +02:00
parent 4da5e6790c
commit 8d6393adf7
2 changed files with 43 additions and 4 deletions
+7
View File
@@ -82,7 +82,13 @@ def main():
tag_counts = {}
candidates = []
media_count = {"image": 0, "video": 0, "gifv": 0, "audio": 0, "total": 0}
for toot in timeline:
for att in toot.get("media_attachments", []):
att_type = att.get("type", "")
media_count["total"] += 1
if att_type in media_count:
media_count[att_type] += 1
if toot.get("language") != "cs":
continue
if "@" in toot.get("account", {}).get("acct", ""):
@@ -151,6 +157,7 @@ def main():
"top": top,
"tags": tags,
"top_links": top_links,
"media_count": media_count,
}, f, ensure_ascii=False, indent=2)
print(f"Uloženo: {out_path} ({len(timeline)} tootů načteno, {len(top)} top, {len(tags)} hashtagů)")
+36 -4
View File
@@ -127,7 +127,8 @@ 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,
total_count=0, top_author=None, newest_account=None, top_links=None):
total_count=0, top_author=None, newest_account=None, top_links=None,
media_count=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)
@@ -173,6 +174,12 @@ def build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, inst
else:
links_sekce = ""
if media_count and media_count.get("total"):
videos = media_count.get("video", 0) + media_count.get("gifv", 0)
media_line = f"📸 Sdílená média: {media_count['total']} ({media_count.get('image', 0)} fotek, {videos} videí)\n"
else:
media_line = ""
return (
f"🐘 Měsíční přehled Mamutovo.cz\n"
f"📅 {format_month_cs(date_to)}\n"
@@ -181,6 +188,7 @@ def build_monthly_toot(measures_data, tags, top_tooty, date_to, prev_stats, inst
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"{media_line}"
f"\n"
f"📊 Celkem uživatelů: {user_count}\n"
f"🌐 Federovaných instancí: {domain_count}\n"
@@ -195,7 +203,7 @@ 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,
prev_stats=None):
prev_stats=None, media_count=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)
@@ -235,6 +243,12 @@ def build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number,
else:
links_sekce = ""
if media_count and media_count.get("total"):
videos = media_count.get("video", 0) + media_count.get("gifv", 0)
media_line = f"📸 Sdílená média: {media_count['total']} ({media_count.get('image', 0)} fotek, {videos} videí)\n"
else:
media_line = ""
date_from_str = format_date_cs(date_from)
date_to_str = format_date_cs(date_to)
year = date_to.year
@@ -247,6 +261,7 @@ def build_toot(measures_data, tags, top_tooty, date_from, date_to, week_number,
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"{media_line}"
f"\n"
f"🔥 Populární hashtagy:\n"
f"{hashtags}\n"
@@ -346,6 +361,21 @@ def load_top_links_from_data(date_to, days):
pass
return result
def load_media_count_from_data(date_to, days):
totals = {"image": 0, "video": 0, "gifv": 0, "audio": 0, "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)
mc = file_data.get("media_count", {})
for key in totals:
totals[key] += mc.get(key, 0)
except FileNotFoundError:
pass
return totals
def load_newest_account_from_data(date_to, days):
for i in range(days):
day = (date_to - timedelta(days=i)).strftime("%Y-%m-%d")
@@ -416,9 +446,10 @@ def main():
top_author = load_top_author_from_data(date_to, 30)
newest_account = load_newest_account_from_data(date_to, 30)
top_links = load_top_links_from_data(date_to, 30)
media_count = load_media_count_from_data(date_to, 30)
toot = build_monthly_toot(
measures_data, tags, top_tooty, date_to, prev_stats, instance_info,
total_count, top_author, newest_account, top_links,
total_count, top_author, newest_account, top_links, media_count,
)
if args.dry_run:
@@ -482,9 +513,10 @@ def main():
top_author = load_top_author_from_data(date_to, 7)
newest_account = load_newest_account_from_data(date_to, 7)
top_links = load_top_links_from_data(date_to, 7)
media_count = load_media_count_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, prev_stats,
total_count, top_author, newest_account, user_count, top_links, prev_stats, media_count,
)
if args.dry_run: