feat: české hashtagy z timeline, oprava mezery za #

This commit is contained in:
2026-04-27 19:31:59 +02:00
parent 21d77c13ca
commit 1298e391d0
+10 -2
View File
@@ -37,6 +37,7 @@ def api_get(url, token):
def clean_content(content):
text = re.sub(r"<[^>]+>", " ", content)
text = html.unescape(text)
text = re.sub(r"#\s+(\w)", r"#\1", text)
return re.sub(r"\s+", " ", text).strip()
def main():
@@ -56,8 +57,15 @@ def main():
sys.exit(1)
try:
trend_tags = api_get(f"{base_url}/api/v1/trends/tags?limit=5", token)
tags = [t["name"] for t in trend_tags]
timeline = api_get(f"{base_url}/api/v1/timelines/public?local=true&limit=40", token)
tag_counts = {}
for toot in timeline:
if toot.get("language") != "cs":
continue
for tag in toot.get("tags", []):
name = tag["name"]
tag_counts[name] = tag_counts.get(name, 0) + 1
tags = [t for t, _ in sorted(tag_counts.items(), key=lambda x: x[1], reverse=True)[:5]]
except Exception:
tags = []