How to use the demoji.URL function in demoji

To help you get started, weโ€™ve selected a few demoji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DiscordWebsite / discord_logview / api / formatter.py View on Github external
import base64
import html
import re

import demoji
import pendulum

from api.emoji import EMOJI_LIST, EMOJI_REGEX, UNICODE_LIST

if not demoji.last_downloaded_timestamp() or pendulum.now() > \
        (pendulum.instance(demoji.last_downloaded_timestamp()).add(days=7)):
    demoji.download_codes()

demoji.set_emoji_pattern()
# This is taken from the Demoji module, because they decided to make the emoji pattern private
esc = (re.escape(c) for c in sorted(dict(demoji.stream_unicodeorg_emojifile(demoji.URL)), key=len, reverse=True))
UNICODE_EMOJI_PAT = re.compile(r"|".join(esc)).pattern


def _encode_codeblock(m):
    return f'\x1AM{base64.b64encode(m.group(1).encode()).decode()}\x1AM'


def _encode_link(m):
    encoded_1 = base64.b64encode(m.group(1).encode()).decode()
    encoded_2 = base64.b64encode(m.group(2).encode()).decode()
    encoded_3 = f'|{base64.b64encode(m.group(5).encode()).decode()}' if m.group(3) else ''
    return f'\x1AL{encoded_1}|{encoded_2}{encoded_3}\x1AL'


def _encode_url(m):
    return f'\x1AU{base64.b64encode(m.group(1).encode()).decode()}\x1AU'