feat: české hashtagy z timeline, oprava mezery za #
This commit is contained in:
+10
-2
@@ -37,6 +37,7 @@ def api_get(url, token):
|
|||||||
def clean_content(content):
|
def clean_content(content):
|
||||||
text = re.sub(r"<[^>]+>", " ", content)
|
text = re.sub(r"<[^>]+>", " ", content)
|
||||||
text = html.unescape(text)
|
text = html.unescape(text)
|
||||||
|
text = re.sub(r"#\s+(\w)", r"#\1", text)
|
||||||
return re.sub(r"\s+", " ", text).strip()
|
return re.sub(r"\s+", " ", text).strip()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -56,8 +57,15 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
trend_tags = api_get(f"{base_url}/api/v1/trends/tags?limit=5", token)
|
timeline = api_get(f"{base_url}/api/v1/timelines/public?local=true&limit=40", token)
|
||||||
tags = [t["name"] for t in trend_tags]
|
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:
|
except Exception:
|
||||||
tags = []
|
tags = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user