feat: URL tootu a hashtagy v textu
This commit is contained in:
+10
-4
@@ -35,8 +35,7 @@ def api_get(url, token):
|
||||
raise
|
||||
|
||||
def clean_content(content):
|
||||
text = re.sub(r'<a\b[^>]*class="[^"]*hashtag[^"]*"[^>]*>.*?</a>', "", content, flags=re.IGNORECASE)
|
||||
text = re.sub(r"<[^>]+>", " ", text)
|
||||
text = re.sub(r"<[^>]+>", " ", content)
|
||||
text = html.unescape(text)
|
||||
return re.sub(r"\s+", " ", text).strip()
|
||||
|
||||
@@ -56,6 +55,12 @@ def main():
|
||||
except Exception:
|
||||
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]
|
||||
except Exception:
|
||||
tags = []
|
||||
|
||||
candidates = []
|
||||
for s in statuses:
|
||||
if "@" in s.get("account", {}).get("acct", ""):
|
||||
@@ -68,6 +73,7 @@ def main():
|
||||
candidates.append({
|
||||
"acct": s["account"]["acct"],
|
||||
"text": text,
|
||||
"url": s.get("url", ""),
|
||||
"reblogs": reblogs,
|
||||
"favourites": favourites,
|
||||
"score": reblogs + favourites,
|
||||
@@ -81,9 +87,9 @@ def main():
|
||||
out_path = os.path.join("data", f"{today}.json")
|
||||
|
||||
with open(out_path, "w", encoding="utf-8") as f:
|
||||
json.dump({"date": today, "top": top}, f, ensure_ascii=False, indent=2)
|
||||
json.dump({"date": today, "top": top, "tags": tags}, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"Uloženo: {out_path} ({len(top)} tootů)")
|
||||
print(f"Uloženo: {out_path} ({len(top)} tootů, {len(tags)} hashtagů)")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user