How to use the demoji.replace 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
allhands = "Someone actually gets paid to make a %s, a %s, and a %s" % (
        person_tipping_hand,
        man_tipping_hand,
        woman_tipping_hand,
    )
    assert demoji.findall(allhands) == {
        person_tipping_hand: "person tipping hand",
        man_tipping_hand: "man tipping hand",
        woman_tipping_hand: "woman tipping hand",
    }
    assert (
        demoji.replace(allhands)
        == "Someone actually gets paid to make a , a , and a "
    )
    assert (
        demoji.replace(allhands, "X")
        == "Someone actually gets paid to make a X, a X, and a X"
    )
    assert isinstance(demoji.last_downloaded_timestamp(), datetime.datetime)

    # Something for everyone...
    batch = [
        "๐Ÿ˜€",
        "๐Ÿ˜‚",
        "๐Ÿคฉ",
        "๐Ÿค",
        "๐Ÿคข",
        "๐Ÿ™",
        "๐Ÿ˜ซ",
        "๐Ÿ™€",
        "๐Ÿ’“",
        "๐Ÿงก",
github fadhluu / mocking-spongebob-bot / text_transformer.py View on Github external
def removeWords(self):
        self.sentence = demoji.replace(self.sentence)
        finalText = ''
        invisibleChar = [u"\u2800", u"\u2063", u'\xe3', u'\xa4']
        words = [i for j in self.sentence.split() for i in (j, ' ')][:-1]
        for word in words:
            word = word.lower()

            # remove twt username, hashtag, and links
            if word[0] == '@' or word[0] == '#' or word[0:4] == 'http':
                word = word.replace(word, '')
            if word[0:5] == '&':
                word = word.replace(word, '&')
            for ew in self.excludedWords:  # remove unnecassary words
                word = word.replace(ew, '')

            for char in word:
                if char in invisibleChar:  # remove invisible char
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 / api / formatter.py View on Github external
jumbo = (not re.sub(r'(\s)', '', re.sub(jumbo_pat, '', content))) and (len(re.findall(jumbo_pat, content)) < 28)
    emoji_class = 'emoji emoji--large' if jumbo else 'emoji'

    # Custom emojis (<:name:id>)
    content = re.sub(r'&lt;(:.*?:)(\d*)&gt;', fr'<img alt="\1" src="'
                     fr'https://cdn.discordapp.com/emojis/\2.png" title="\1" class="{emoji_class}">', content)

    # Custom animated emojis ()
    content = re.sub(r'&lt;a(:.*?:)(\d*)&gt;', fr'<img alt="\1" src="'
                     fr'https://cdn.discordapp.com/emojis/\2.gif" title="\1" class="{emoji_class}">', content)

    # Process emojis (:text:)
    content = re.sub(EMOJI_REGEX, _process_emojis, content)

    # Process unicode emojis
    content = demoji.replace(content, lambda m: _process_unicode_emojis(m, emoji_class))

    # Process block quotes (&gt; text or &gt;&gt;&gt; te\ntx)
    content = re.sub(r'^&gt; (.+)$|^(?:&gt;){3} ([\S\s]+)$', r'<blockquote>\1\2</blockquote>', content)

    # Process bold (**text**)
    content = re.sub(r'\*\*((?:\\[\s\S]|[^\\])+?)\*\*(?!\*)', r'<b>\1</b>', content)

    # Process underline (__text__)
    content = re.sub(r'__((?:\\[\s\S]|[^\\])+?)__(?!_)', r'<u>\1</u>', content)

    # Process italic (*text* or _text_)
    content = re.sub(r'\b_((?:__|\\[\s\S]|[^\\_])+?)_\b|\*(?=\S)((?:\*\*|\\[\s\S]|\s+(?:\\[\s\S]|[^\s*\\]|\*\*)|'
                     r'[^\s*\\])+?)\*(?!\*)', r'<i>\1\2</i>', content)

    # Process strike through (~~text~~)
    content = re.sub(r'~~(?=\S)((?:\\[\s\S]|~(?!~)|[^\s\\~]|\s+(?!~~))+?)~~', r'<s>\1</s>', content)
github DiscordWebsite / discord_logview / django_logs / formatter.py View on Github external
# Process emojis (:text:)
    content = re.sub(EMOJI_REGEX, process_emojis, content)

    def process_unicode_emojis(m):
        e = m.group()
        e = re.sub(r'[\U0000FE00-\U0000FE0F]$', '', e)
        title_e = re.sub(r'[\U0001F3FB-\U0001F3FF]$', '', e)
        if not title_e:
            title_e = e
        title = UNICODE_LIST.get(title_e) or demoji._CODE_TO_DESC[title_e]
        codepoint = "-".join(['%04x' % ord(_c) for _c in e]).lstrip('0')
        return fr'<img alt="{e}" title=":{title}:" class="emoji">'

    # Process unicode emojis
    content = demoji.replace(content, process_unicode_emojis)

    # Process bold (**text**)
    content = re.sub(r'\*\*((?:\\[\s\S]|[^\\])+?)\*\*(?!\*)', r'<b>\1</b>', content)

    # Process underline (__text__)
    content = re.sub(r'__((?:\\[\s\S]|[^\\])+?)__(?!_)', r'<u>\1</u>', content)

    # Process italic (*text* or _text_)
    content = re.sub(r'\b_((?:__|\\[\s\S]|[^\\_])+?)_\b|\*(?=\S)((?:\*\*|\\[\s\S]|\s+(?:\\[\s\S]|[^\s*\\]|\*\*)|'
                     r'[^\s*\\])+?)\*(?!\*)', r'<i>\1\2</i>', content)

    # Process strike through (~~text~~)
    content = re.sub(r'~~(?=\S)((?:\\[\s\S]|~(?!~)|[^\s\\~]|\s+(?!~~))+?)~~', r'<s>\1</s>', content)

    # Decode and process links
    def decode_url(m):
github DiscordWebsite / discord_logview / django_logs / formatter.py View on Github external
content = re.sub(EMOJI_REGEX, process_emojis, content)

    def process_unicode_emojis(m):
        e = m.group()
        e = re.sub(r'[\U0000FE00-\U0000FE0F]$', '', e)
        title_e = re.sub(r'[\U0001F3FB-\U0001F3FF]$', '', e)
        if not title_e:
            title_e = e
        title = UNICODE_LIST.get(title_e) or demoji._CODE_TO_DESC[title_e]
        emoji_class = 'emoji emoji--large' if jumbo else 'emoji'
        codepoint = "-".join(['%04x' % ord(_c) for _c in e]).lstrip('0')
        return fr'<img alt="{e}" title=":{title}:" class="{emoji_class}">'

    # Process unicode emojis
    content = demoji.replace(content, process_unicode_emojis)

    # Process block quotes (&gt; text or &gt;&gt;&gt; te\ntx)
    content = re.sub(r'^&gt; (.+)$|^(?:&gt;){3} ([\S\s]+)$', r'<blockquote>\1\2</blockquote>', content)

    # Process bold (**text**)
    content = re.sub(r'\*\*((?:\\[\s\S]|[^\\])+?)\*\*(?!\*)', r'<b>\1</b>', content)

    # Process underline (__text__)
    content = re.sub(r'__((?:\\[\s\S]|[^\\])+?)__(?!_)', r'<u>\1</u>', content)

    # Process italic (*text* or _text_)
    content = re.sub(r'\b_((?:__|\\[\s\S]|[^\\_])+?)_\b|\*(?=\S)((?:\*\*|\\[\s\S]|\s+(?:\\[\s\S]|[^\s*\\]|\*\*)|'
                     r'[^\s*\\])+?)\*(?!\*)', r'<i>\1\2</i>', content)

    # Process strike through (~~text~~)
    content = re.sub(r'~~(?=\S)((?:\\[\s\S]|~(?!~)|[^\s\\~]|\s+(?!~~))+?)~~', r'<s>\1</s>', content)