BlueGit

ict rusty-teams

Files

rusty-teams / scripts / teams-emotions.py

teams-emotions.py

teams-emotions.py 1.2 KiB Download Raw
1#!/usr/bin/env python3
2"""Build crates/chatsvc/assets/emotions.tsv from the Teams emoticon catalog.
3
4Usage: scripts/teams-emotions.py <en-us.json>
5Source: https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v1/metadata/<emoticonAssetVersion>/en-us.json (version in the Teams web config).
6Line: glyph without U+FE0F <TAB> Teams keys (space), catalog order, first key primary.
7"""
8import json
9import pathlib
10import sys
11
12catalog_path = pathlib.Path(sys.argv[1])
13repo_root = pathlib.Path(__file__).resolve().parent.parent
14output_path = repo_root / "crates/chatsvc/assets/emotions.tsv"
15
16catalog = json.loads(catalog_path.read_text(encoding="utf-8"))
17keys_by_glyph = {}
18for category in catalog["categories"]:
19 for emoticon in category["emoticons"]:
20 glyph = emoticon.get("unicode", "").replace("️", "")
21 key = emoticon.get("id", "")
22 if not glyph or not key:
23 continue
24 keys = keys_by_glyph.setdefault(glyph, [])
25 if key not in keys:
26 keys.append(key)
27
28lines = [f"{glyph}\t{' '.join(keys)}" for glyph, keys in keys_by_glyph.items()]
29output_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
30print(f"{len(lines)} glyphs -> {output_path}")