How to use the demoji.download_codes 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 bsolomon1124 / demoji / tests / test_demoji.py View on Github external
def test_download():
    assert demoji.download_codes() is None
    assert type(demoji._EMOJI_PAT) == type(re.compile(""))  # noqa
    assert isinstance(demoji._CODE_TO_DESC, dict)
    assert os.path.isfile(demoji.CACHEPATH)
github fzxiao233 / live_monitor_worker / worker / tools.py View on Github external
def remove_emoji(self):
        # emoji_pattern = re.compile(
        #     u'(\U0001F1F2\U0001F1F4)|'  # Macau flag
        #     u'([\U0001F1E6-\U0001F1FF]{2})|'  # flags
        #     u'([\U0001F600-\U0001F64F])'  # emoticons
        #     "+", flags=re.UNICODE)
        # self.filename = emoji_pattern.sub('', self.filename)
        try:
            self.filename = demoji.replace(self.filename, '#')
        except IOError:
            demoji.download_codes()
github DiscordWebsite / discord_logview / django_logs / formatter.py View on Github external
import base64
import html
import re
from datetime import timedelta, datetime

import demoji
import pytz

from django_logs.emoji import EMOJI_LIST, EMOJI_REGEX, UNICODE_LIST

if not demoji.last_downloaded_timestamp() or datetime.now(pytz.UTC) > \
        (demoji.last_downloaded_timestamp() + timedelta(days=7)):
    demoji.download_codes()

if not demoji._EMOJI_PAT:
    demoji.set_emoji_pattern()


def format_content_html(content: str, users: dict = None, masked_links: bool = False, newlines: bool = True) -> str:
    # HTML-encode content

    def encode_codeblock(m):
        encoded = base64.b64encode(m.group(1).encode()).decode()
        return '\x1AM' + encoded + '\x1AM'

    # Encode multiline codeblocks (```text```)
    content = re.sub(r'```+((?:[^`]*?\n)?(?:[\s\S]+))\n?```+', encode_codeblock, content)

    # Encode links
github DiscordWebsite / discord_logview / api / formatter.py View on Github external
modified by https://github.com/EJH2
ยฉ 2019 EJH2
"""

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'