script.py


import requests
from bs4 import BeautifulSoup
import json

URL = "https://slackmojis.com/categories/25-blob-cats-emojis"
def fetch_emoji_map():
    response = requests.get(URL)
    response.raise_for_status()

    soup = BeautifulSoup(response.text, "html.parser")
    emojis = soup.select("li.emoji")

    emoji_map = {}
    for emoji in emojis:
        img = emoji.find("img")
        if img and img.get("src"):
            # Extract emoji name from the li class attribute
            classes = emoji.get("class", [])
            emoji_name = None
            for cls in classes:
                if cls != "emoji":  # Skip the generic "emoji" class
                    emoji_name = cls
                    break
            
            # Fallback: extract from title attribute
            if not emoji_name:
                emoji_name = emoji.get("title")
            
            if emoji_name:
                src = img["src"]
                emoji_map[emoji_name] = src
    return emoji_map


def generate_results(input_file="emojis.txt", output_file="owo.json"):
    emoji_map = fetch_emoji_map()
    container = []

    # If input file exists, process it
    try:
        with open(input_file, "r", encoding="utf-8") as f:
            for line in f:
                name = line.strip()
                if not name:
                    continue
                if name in emoji_map:
                    container.append({
                        "icon": f'<img src="{emoji_map[name]}">',
                        "text": name
                    })
                else:
                    container.append({
                        "icon": None,
                        "text": name,
                        "error": "Not found"
                    })
    except FileNotFoundError:
        # If no input file, use all emojis from the website
        for name, src in emoji_map.items():
            container.append({
                "icon": f'<img src="{src}">',
                "text": name
            })

    # Create the nested structure to match owo.json format
    results = {
        "Blobcat": {
            "type": "image",
            "container": container
        }
    }

    # Write results to JSON file
    with open(output_file, "w", encoding="utf-8") as f:
        json.dump(results, f, ensure_ascii=False, indent=2)
    
    print(f"Results saved to {output_file}")


if __name__ == "__main__":
    generate_results()