Skip to content

Update emoji list (emojilib 4.0.1) #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devnoname120
Copy link

@devnoname120 devnoname120 commented Feb 1, 2025

Not sure if I should commit it, here is the Python script I used to generate the new version.

File emojis-generator.py:

#!/usr/bin/env python3
import json
import requests

def download_json(url):
    response = requests.get(url, timeout=10)
    response.raise_for_status()
    return response.json()

def get_code_point(emoji):
    return " ".join(f"{ord(char):X}" for char in emoji)

def escape_string(s):
    return '"' + s.replace('\\', '\\\\').replace('"', '\\"') + '"'

TEMPLATE = """package turtle

// Emoji holds info about an emoji character
type Emoji struct {{
    Name     string   `json:"name" toml:"name"`
    Category string   `json:"category" toml:"category"`
    Char     string   `json:"char" toml:"char"`
    Keywords []string `json:"keywords" toml:"keywords"`
}}

// String implementation for Emoji
func (e Emoji) String() string {{
    return e.Char
}}

// emojis holds all available Emoji
var emojis = []*Emoji{{
{emoji_entries}
}}
"""

ENTRY_TEMPLATE = """    {{
        Name:     {name},
        Category: {category},
        Char:     {char},
        Keywords: []string{{{keywords}}},
    }},"""

def main():
    emoji_keywords_url = "https://github.com/muan/emojilib/raw/refs/heads/main/dist/emoji-en-US.json"
    emoji_data_url = "https://github.com/muan/unicode-emoji-json/raw/refs/heads/main/data-by-emoji.json"

    emoji_keywords = download_json(emoji_keywords_url)
    emoji_data = download_json(emoji_data_url)

    emoji_info = {}
    for emoji_symbol, keywords in emoji_keywords.items():
        if emoji_symbol in emoji_data:
            emoji_data[emoji_symbol]['codepoint'] = get_code_point(emoji_symbol)
            emoji_data[emoji_symbol]['keywords'] = keywords
            emoji_info[emoji_symbol] = emoji_data[emoji_symbol]

    emoji_entries = "\n".join(
        ENTRY_TEMPLATE.format(
            name=escape_string(info.get("slug", "")),
            category=escape_string(info.get("group", "")),
            char=escape_string(char),
            keywords=", ".join(escape_string(kw) for kw in info.get("keywords", []))
        )
        for char, info in emoji_info.items()
    )
    go_code = TEMPLATE.format(emoji_entries=emoji_entries)
    print(go_code)

if __name__ == "__main__":
    main()

I ran it with ./emojis-generator.py > emojis.go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant