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:
@@ -82,7 +82,13 @@ def main():
|
|||||||
|
|
||||||
tag_counts = {}
|
tag_counts = {}
|
||||||
candidates = []
|
candidates = []
|
||||||
|
media_count = {"image": 0, "video": 0, "gifv": 0, "audio": 0, "total": 0}
|
||||||
for toot in timeline:
|
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":
|
if toot.get("language") != "cs":
|
||||||
continue
|
continue
|
||||||
if "@" in toot.get("account", {}).get("acct", ""):
|
if "@" in toot.get("account", {}).get("acct", ""):
|
||||||
@@ -151,6 +157,7 @@ def main():
|
|||||||
"top": top,
|
"top": top,
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
"top_links": top_links,
|
"top_links": top_links,
|
||||||
|
"media_count": media_count,
|
||||||
}, f, ensure_ascii=False, indent=2)
|
}, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
print(f"Uloženo: {out_path} ({len(timeline)} tootů načteno, {len(top)} top, {len(tags)} hashtagů)")
|
print(f"Uloženo: {out_path} ({len(timeline)} tootů načteno, {len(top)} top, {len(tags)} hashtagů)")
|
||||||
|
|||||||
+36
-4
@@ -127,7 +127,8 @@ def format_month_cs(dt):
|
|||||||
return f"{months[dt.month - 1]} {dt.year}"
|
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, 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}
|
stats = {m["key"]: int(m["total"]) for m in measures_data}
|
||||||
new_users = stats.get("new_users", 0)
|
new_users = stats.get("new_users", 0)
|
||||||
active_users = stats.get("active_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:
|
else:
|
||||||
links_sekce = ""
|
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 (
|
return (
|
||||||
f"🐘 Měsíční přehled Mamutovo.cz\n"
|
f"🐘 Měsíční přehled Mamutovo.cz\n"
|
||||||
f"📅 {format_month_cs(date_to)}\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"✅ Aktivní uživatelé: {active_users}{fmt_diff(active_users, 'active_users')}\n"
|
||||||
f"📝 Interakce: {interactions}{fmt_diff(interactions, 'interactions')}\n"
|
f"📝 Interakce: {interactions}{fmt_diff(interactions, 'interactions')}\n"
|
||||||
f"📝 Tooty měsíce: {total_count}\n"
|
f"📝 Tooty měsíce: {total_count}\n"
|
||||||
|
f"{media_line}"
|
||||||
f"\n"
|
f"\n"
|
||||||
f"📊 Celkem uživatelů: {user_count}\n"
|
f"📊 Celkem uživatelů: {user_count}\n"
|
||||||
f"🌐 Federovaných instancí: {domain_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,
|
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):
|
prev_stats=None, media_count=None):
|
||||||
stats = {m["key"]: int(m["total"]) for m in measures_data}
|
stats = {m["key"]: int(m["total"]) for m in measures_data}
|
||||||
new_users = stats.get("new_users", 0)
|
new_users = stats.get("new_users", 0)
|
||||||
active_users = stats.get("active_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:
|
else:
|
||||||
links_sekce = ""
|
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_from_str = format_date_cs(date_from)
|
||||||
date_to_str = format_date_cs(date_to)
|
date_to_str = format_date_cs(date_to)
|
||||||
year = date_to.year
|
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"✅ Aktivní uživatelé: {active_users}{fmt_diff(active_users, 'active_users')}\n"
|
||||||
f"📝 Interakce: {interactions}{fmt_diff(interactions, 'interactions')}\n"
|
f"📝 Interakce: {interactions}{fmt_diff(interactions, 'interactions')}\n"
|
||||||
f"📝 Tooty týdne: {total_count}\n"
|
f"📝 Tooty týdne: {total_count}\n"
|
||||||
|
f"{media_line}"
|
||||||
f"\n"
|
f"\n"
|
||||||
f"🔥 Populární hashtagy:\n"
|
f"🔥 Populární hashtagy:\n"
|
||||||
f"{hashtags}\n"
|
f"{hashtags}\n"
|
||||||
@@ -346,6 +361,21 @@ def load_top_links_from_data(date_to, days):
|
|||||||
pass
|
pass
|
||||||
return result
|
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):
|
def load_newest_account_from_data(date_to, days):
|
||||||
for i in range(days):
|
for i in range(days):
|
||||||
day = (date_to - timedelta(days=i)).strftime("%Y-%m-%d")
|
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)
|
top_author = load_top_author_from_data(date_to, 30)
|
||||||
newest_account = load_newest_account_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)
|
top_links = load_top_links_from_data(date_to, 30)
|
||||||
|
media_count = load_media_count_from_data(date_to, 30)
|
||||||
toot = build_monthly_toot(
|
toot = build_monthly_toot(
|
||||||
measures_data, tags, top_tooty, date_to, prev_stats, instance_info,
|
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:
|
if args.dry_run:
|
||||||
@@ -482,9 +513,10 @@ def main():
|
|||||||
top_author = load_top_author_from_data(date_to, 7)
|
top_author = load_top_author_from_data(date_to, 7)
|
||||||
newest_account = load_newest_account_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)
|
top_links = load_top_links_from_data(date_to, 7)
|
||||||
|
media_count = load_media_count_from_data(date_to, 7)
|
||||||
toot = build_toot(
|
toot = build_toot(
|
||||||
measures_data, tags, top_tooty, date_from, date_to, week_number,
|
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:
|
if args.dry_run:
|
||||||
|
|||||||
Reference in New Issue
Block a user