feat: kategorie z featured_tags, přidány sport a politika
This commit is contained in:
@@ -218,6 +218,12 @@
|
|||||||
<p>Hashtagy jsou na Mastodonu důležité – slouží k objevování obsahu. Přidávej je na konec tootů. Můžeš sledovat i samotný hashtag a jeho příspěvky se ti budou zobrazovat v timeline. Příklady: <code>#cesky</code> <code>#fotografie</code> <code>#linux</code></p>
|
<p>Hashtagy jsou na Mastodonu důležité – slouží k objevování obsahu. Přidávej je na konec tootů. Můžeš sledovat i samotný hashtag a jeho příspěvky se ti budou zobrazovat v timeline. Příklady: <code>#cesky</code> <code>#fotografie</code> <code>#linux</code></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="section">
|
||||||
|
<h2>Zvýrazněné hashtagy</h2>
|
||||||
|
<p>Nastav si zvýrazněné hashtagy – zobrazí se na tvém profilu a v seznamu CZ/SK účtů na <a href="https://fedi.mamutovo.cz">fedi.mamutovo.cz</a>.</p>
|
||||||
|
<p style="margin-top:0.5rem;">Jak na to: <code>Předvolby → Profil → Zvýrazněné hashtagy</code></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h2>Užitečné odkazy</h2>
|
<h2>Užitečné odkazy</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
+16
-1
@@ -222,9 +222,18 @@ CATEGORIES = {
|
|||||||
"kultura": ["knihy", "literatura", "film", "hudba", "divadlo", "umění"],
|
"kultura": ["knihy", "literatura", "film", "hudba", "divadlo", "umění"],
|
||||||
"gaming": ["gaming", "hry", "videohry", "steam", "gamer"],
|
"gaming": ["gaming", "hry", "videohry", "steam", "gamer"],
|
||||||
"zpravy": ["novinář", "zprávy", "politik", "média", "journalist"],
|
"zpravy": ["novinář", "zprávy", "politik", "média", "journalist"],
|
||||||
|
"sport": ["sport", "fotbal", "hokej", "cycling", "running", "fitness", "tenis", "atletika"],
|
||||||
|
"politika": ["politika", "politics", "czech", "democracy", "volby", "eu"],
|
||||||
}
|
}
|
||||||
|
|
||||||
def categorize(acc):
|
def categorize(acc):
|
||||||
|
# Primárně matchuj featured_tags proti CATEGORIES
|
||||||
|
for tag in acc.get("_featured_tags", []):
|
||||||
|
tag_lower = tag.lower()
|
||||||
|
for cat, kws in CATEGORIES.items():
|
||||||
|
if any(kw in tag_lower for kw in kws):
|
||||||
|
return cat
|
||||||
|
# Fallback: bio text + display_name
|
||||||
text = re.sub(r"<[^>]+>", " ", acc.get("note", "") or "").lower()
|
text = re.sub(r"<[^>]+>", " ", acc.get("note", "") or "").lower()
|
||||||
text += " " + (acc.get("display_name", "") or "").lower()
|
text += " " + (acc.get("display_name", "") or "").lower()
|
||||||
for cat, kws in CATEGORIES.items():
|
for cat, kws in CATEGORIES.items():
|
||||||
@@ -233,16 +242,22 @@ def categorize(acc):
|
|||||||
return "ostatni"
|
return "ostatni"
|
||||||
|
|
||||||
def fetch_featured_tags(acc):
|
def fetch_featured_tags(acc):
|
||||||
|
if "_featured_tags" in acc:
|
||||||
|
return acc["_featured_tags"]
|
||||||
account_id = acc.get("id")
|
account_id = acc.get("id")
|
||||||
instance = acc.get("_source_instance", "")
|
instance = acc.get("_source_instance", "")
|
||||||
if not account_id or not instance:
|
if not account_id or not instance:
|
||||||
|
acc["_featured_tags"] = []
|
||||||
return []
|
return []
|
||||||
url = f"https://{instance}/api/v1/accounts/{account_id}/featured_tags"
|
url = f"https://{instance}/api/v1/accounts/{account_id}/featured_tags"
|
||||||
token = _token_for(instance)
|
token = _token_for(instance)
|
||||||
data = api_get(url, token=token)
|
data = api_get(url, token=token)
|
||||||
if not data or not isinstance(data, list):
|
if not data or not isinstance(data, list):
|
||||||
|
acc["_featured_tags"] = []
|
||||||
return []
|
return []
|
||||||
return [t["name"] for t in data if isinstance(t, dict) and t.get("name")][:4]
|
tags = [t["name"] for t in data if isinstance(t, dict) and t.get("name")][:4]
|
||||||
|
acc["_featured_tags"] = tags
|
||||||
|
return tags
|
||||||
|
|
||||||
# ── VÝSTUP ────────────────────────────────────
|
# ── VÝSTUP ────────────────────────────────────
|
||||||
def _to_output(acc):
|
def _to_output(acc):
|
||||||
|
|||||||
Reference in New Issue
Block a user