python icon indicating copy to clipboard operation
python copied to clipboard

[unicode_emoji] Add aliases from Emojipedia

Open tyilo opened this issue 4 years ago • 4 comments

Add list of aliases scraped from Emojipedia using following script:

import asyncio
import json
import re

from requests_html import AsyncHTMLSession
from rich.progress import track

LINE_RE = re.compile(
    r"""
    ^
    (?P<codepoints> .*\S)
    \s*;\s*
    (?P<status> \S+)
    \s*\#\s*
    (?P<emoji> \S+)
    \s*
    (?P<version> E\d+.\d+)
    \s*
    (?P<name> .+)
    $
""",
    re.VERBOSE,
)


async def get_aliases(session, name):
    emojipedia_name = name.replace(" ", "-")
    url = f"https://emojipedia.org/{emojipedia_name}/"
    r = await session.get(url)
    if r.status_code != 200:
        return (name, [])

    aliases = r.html.find(".aliases li")
    res = []
    for alias in aliases:
        alias = alias.text.split(maxsplit=1)[1]
        alias = alias.replace("\N{NO-BREAK SPACE}", " ")  # Replace nbsp
        res.append(alias)
    return (name, res)


async def main():
    session = AsyncHTMLSession()
    aliases = {}

    aws = []
    with open("emoji-test.txt") as f:
        for l in f:
            if m := LINE_RE.match(l):
                d = m.groupdict()
                if d["status"] != "fully-qualified":
                    continue

                aws.append(get_aliases(session, d["name"]))

    for aw in track(asyncio.as_completed(aws), total=len(aws)):
        name, res = await aw
        if res:
            aliases[name] = res

        print(name, res)

    with open("aliases.json", "w") as f:
        json.dump(aliases, f)


asyncio.run(main())

tyilo avatar Dec 15 '20 21:12 tyilo

May be my fault but please clean up the git mess

ManuelSchneid3r avatar Dec 17 '20 01:12 ManuelSchneid3r

@ManuelSchneid3r should be fixed now.

tyilo avatar Dec 19 '20 18:12 tyilo

@ManuelSchneid3r ping

tyilo avatar Jan 24 '21 01:01 tyilo

Ping

tyilo avatar Mar 09 '21 12:03 tyilo

0.18 is out. Please check the new api . Do you mind to volunteer as a maintainer for the plugin?

ManuelSchneid3r avatar Jan 03 '23 19:01 ManuelSchneid3r

0.18 is out. Please check the new api . Do you mind to volunteer as a maintainer for the plugin?

Sure.

I created a new PR for it: https://github.com/albertlauncher/python/pull/139

tyilo avatar Jan 03 '23 22:01 tyilo