| 1 | #!/usr/bin/env python3 |
| 2 | """Build crates/chatsvc/assets/emotions.tsv from the Teams emoticon catalog. |
| 3 | |
| 4 | Usage: scripts/teams-emotions.py <en-us.json> |
| 5 | Source: https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v1/metadata/<emoticonAssetVersion>/en-us.json (version in the Teams web config). |
| 6 | Line: glyph without U+FE0F <TAB> Teams keys (space), catalog order, first key primary. |
| 7 | """ |
| 8 | import json |
| 9 | import pathlib |
| 10 | import sys |
| 11 | |
| 12 | catalog_path = pathlib.Path(sys.argv[1]) |
| 13 | repo_root = pathlib.Path(__file__).resolve().parent.parent |
| 14 | output_path = repo_root / "crates/chatsvc/assets/emotions.tsv" |
| 15 | |
| 16 | catalog = json.loads(catalog_path.read_text(encoding="utf-8")) |
| 17 | keys_by_glyph = {} |
| 18 | for 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 | |
| 28 | lines = [f"{glyph}\t{' '.join(keys)}" for glyph, keys in keys_by_glyph.items()] |
| 29 | output_path.write_text("\n".join(lines) + "\n", encoding="utf-8") |
| 30 | print(f"{len(lines)} glyphs -> {output_path}") |