diff --git a/daily_top.py b/daily_top.py index 1ba5cd5..4437350 100644 --- a/daily_top.py +++ b/daily_top.py @@ -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 = []