feat: kategorie z featured_tags, přidány sport a politika

This commit is contained in:
2026-04-11 12:43:11 +02:00
parent 1944c56d9c
commit 83992f6112
2 changed files with 28 additions and 7 deletions
+6
View File
@@ -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>
</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">
<h2>Užitečné odkazy</h2>
<ul>
+22 -7
View File
@@ -216,15 +216,24 @@ def score(acc):
# ── KATEGORIE ─────────────────────────────────
CATEGORIES = {
"tech": ["linux", "python", "programov", "software", "opensource", "developer", "sysadmin", "git"],
"foto": ["fotografi", "foto", "photograph", "objektiv", "kamera"],
"veda": ["věda", "fyzika", "biologi", "astronom", "výzkum", "science", "matematik"],
"kultura": ["knihy", "literatura", "film", "hudba", "divadlo", "umění"],
"gaming": ["gaming", "hry", "videohry", "steam", "gamer"],
"zpravy": ["novinář", "zprávy", "politik", "média", "journalist"],
"tech": ["linux", "python", "programov", "software", "opensource", "developer", "sysadmin", "git"],
"foto": ["fotografi", "foto", "photograph", "objektiv", "kamera"],
"veda": ["věda", "fyzika", "biologi", "astronom", "výzkum", "science", "matematik"],
"kultura": ["knihy", "literatura", "film", "hudba", "divadlo", "umění"],
"gaming": ["gaming", "hry", "videohry", "steam", "gamer"],
"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):
# 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 += " " + (acc.get("display_name", "") or "").lower()
for cat, kws in CATEGORIES.items():
@@ -233,16 +242,22 @@ def categorize(acc):
return "ostatni"
def fetch_featured_tags(acc):
if "_featured_tags" in acc:
return acc["_featured_tags"]
account_id = acc.get("id")
instance = acc.get("_source_instance", "")
if not account_id or not instance:
acc["_featured_tags"] = []
return []
url = f"https://{instance}/api/v1/accounts/{account_id}/featured_tags"
token = _token_for(instance)
data = api_get(url, token=token)
if not data or not isinstance(data, list):
acc["_featured_tags"] = []
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 ────────────────────────────────────
def _to_output(acc):