def test_replace_emoji(): assert emoji.replace_emoji(u'Hi, I am fine. 😁') == 'Hi, I am fine. ' assert emoji.replace_emoji('Hi') == 'Hi' assert emoji.replace_emoji('Hello 🇫🇷👌') == 'Hello ' assert emoji.replace_emoji('Hello 🇫🇷👌', 'x') == 'Hello xx' def replace(emj, data): assert emj in ["🇫🇷", "👌"] return 'x' assert emoji.replace_emoji('Hello 🇫🇷👌', replace) == 'Hello xx'
def convert(self, md_input, article_id, new_id, article_data): md = replace_emoji(md_input) md = self.process_linked_items(md, article_id, new_id) if len(article_data.article_data['article']['attachments']) > 0: self.process_attachments(new_id, article_data) md = md + u'\n' + self.attachment_table.to_md() md = self.convert_math_blocks(md) md = self.develop_dss_links(md) html = markdown.markdown(md, extensions=[ 'markdown.extensions.tables', 'markdown.extensions.fenced_code', 'markdown.extensions.nl2br', 'markdown.extensions.extra', WikiLinkExtension() ]) html = self.convert_alert_div_blocks(html) html = self.convert_dss_refs_in_wikilinks(html) html = convert_info_macros(html) html = convert_comment_block(html) html = convert_code_block(html) html = process_refs(html) html = add_images(new_id, self.studio_external_url, self.confluence_url, html, self.confluence_username, self.confluence_password) return html
def render_template(self, name: str, *args, **kwargs) -> str: kwargs["request"] = self text = render_template(name, *args, **kwargs) if self.cert.emoji_mode == 1: text = emoji.demojize(text) elif self.cert.emoji_mode == 2: text = emoji.replace_emoji(text) # type: ignore return text
def render_template(self, name: str, *args, **kwargs) -> str: kwargs["request"] = self text = template_env.get_template(name).render(*args, **kwargs) if self.cert.emoji_mode == 1: text = emoji.demojize(text) elif self.cert.emoji_mode == 2: text = emoji.replace_emoji(text) return text
def test_method_replace_version(): # Test method "emoji.replace_emoji(string, version=X.Y)" assert emoji.replace_emoji( u"\U0001F40D\U0001F9E0\U0001FAC2\U0001FAD7\U0001FAC2", version=6) == u"\U0001F40D\U0001F9E0" assert emoji.replace_emoji(u'Hi, I am fine. 😁', version=0) == u'Hi, I am fine. ' assert emoji.replace_emoji(u'Hi', version=0) == u'Hi' assert emoji.replace_emoji(u'Hello 🇫🇷👌', version=0) == u'Hello ' assert emoji.replace_emoji( u'Hello 🇫🇷👌', u'x', version=0, ) == u'Hello xx' assert emoji.replace_emoji( u'Hello 🇫🇷👌', u'x', version=1, ) == u'Hello 🇫🇷👌' def replace(emj, data): assert emj in [u"🇫🇷", u"👌"] return u'x' assert emoji.replace_emoji(u'Hello 🇫🇷👌', replace, version=0.1) == u'Hello xx'
def clean_text(text): #remove emojis, remove links, anonymize user mentions clean = "" text = emoji.replace_emoji(text, replacement=' ') for t in text.split(" "): if t.startswith('@') and len(t) > 1: clean += "@user " elif t == '' or t.startswith('http'): pass else: clean += t + " " return clean
async def translateme(trans): """For .trt command, translate the given text using Google Translate.""" translator = Translator() textx = await trans.get_reply_message() message = trans.pattern_match.group(1) if message: pass elif textx: message = textx.text else: return await trans.edit( "`Give a text or reply to a message to translate!`") try: from userbot.modules.sql_helper.globals import gvarstatus except AttributeError: return await trans.edit("`Running on Non-SQL mode!`") if gvarstatus("trt_lang") is not None: target_lang = str(gvarstatus("trt_lang")) else: target_lang = "en" try: reply_text = translator.translate(replace_emoji(message), dest=target_lang) except ValueError: return await trans.edit("Invalid destination language.") source_lan = LANGUAGES[f"{reply_text.src.lower()}"] transl_lan = LANGUAGES[f"{reply_text.dest.lower()}"] reply_text = f"From **{source_lan.title()}**\nTo **{transl_lan.title()}:**\n\n{reply_text.text}" await trans.edit(reply_text) if BOTLOG: await trans.client.send_message( BOTLOG_CHATID, f"Translated some {source_lan.title()} stuff to {transl_lan.title()} just now.", )
def replaceEmoji(inputString): string = emoji.replace_emoji(inputString, replace='') return string
def test_replace_emoji(): assert emoji.replace_emoji('Hi, I am fine. 😁') == 'Hi, I am fine. ' assert emoji.replace_emoji('Hi') == 'Hi' assert emoji.replace_emoji('Hello 🇫🇷👌') == 'Hello ' assert emoji.replace_emoji('Hello 🇫🇷👌', 'x') == 'Hello xx'
def test_text(): UCS2 = len('Hello 🇫🇷👌') > 9 # don't break up characters on python with UCS-2 text = u"""Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat in reprehenderit in cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Stróż pchnął kość w quiz gędźb vel fax myjń. Høj bly gom vandt fræk sexquiz på wc. Съешь же ещё этих мягких французских булок, да выпей чаю. За миг бях в чужд плюшен скърцащ фотьойл. هلا سكنت بذي ضغثٍ فقد زعموا — شخصت تطلب ظبياً راح مجتازا שפן אכל קצת גזר בטעם חסה, ודי ऋषियों को सताने वाले दुष्ट राक्षसों के राजा रावण का सर्वनाश करने वाले विष्णुवतार भगवान श्रीराम, अयोध्या के महाराज दशरथ के बड़े सपुत्र थे। とりなくこゑす ゆめさませ みよあけわたる ひんかしを そらいろはえて おきつへに ほふねむれゐぬ もやのうち 視野無限廣,窗外有藍天 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. """ def add_random_emoji(text, lst, select=lambda emj_data: emj_data['en']): emoji_list = [] text_with_unicode = u"" text_with_placeholder = u"" for i in range(0, len(text), 10): while True: emj, emj_data = random.choice(lst) placeholder = select(emj_data) if placeholder: break if UCS2: j = text.find(u" ", i, i + 10) if j == -1: continue else: j = random.randint(i, i + 10) text_with_unicode += text[i:j] text_with_unicode += emj text_with_unicode += text[j:i + 10] text_with_placeholder += text[i:j] text_with_placeholder += placeholder text_with_placeholder += text[j:i + 10] emoji_list.append(emj) return text_with_unicode, text_with_placeholder, emoji_list def clean(s): return s.replace(u'\u200d', '').replace(u'\ufe0f', '') all_emoji_list = list(emoji.EMOJI_DATA.items()) qualified_emoji_list = [(emj, item) for emj, item in emoji.EMOJI_DATA.items() if item['status'] == emoji.STATUS['fully_qualified']] # qualified emoji text_with_unicode, text_with_placeholder, emoji_list = add_random_emoji(text, qualified_emoji_list) assert emoji.demojize(text_with_unicode) == text_with_placeholder assert emoji.emojize(text_with_placeholder) == text_with_unicode if not UCS2: assert emoji.replace_emoji(text_with_unicode, u'') == text assert set(emoji.distinct_emoji_list(text_with_unicode)) == set(emoji_list) for i, lis in enumerate(emoji.emoji_list(text_with_unicode)): assert lis['emoji'] == emoji_list[i] # qualified emoji from "es" selector = lambda emoji_data: emoji_data["es"] if "es" in emoji_data else False text_with_unicode, text_with_placeholder, emoji_list = add_random_emoji(text, qualified_emoji_list, selector) assert emoji.demojize(text_with_unicode, language="es") == text_with_placeholder assert emoji.emojize(text_with_placeholder, language="es") == text_with_unicode if not UCS2: assert emoji.replace_emoji(text_with_unicode, u'') == text assert set(emoji.distinct_emoji_list(text_with_unicode)) == set(emoji_list) for i, lis in enumerate(emoji.emoji_list(text_with_unicode)): assert lis['emoji'] == emoji_list[i] # qualified emoji from "alias" selector = lambda emoji_data: emoji_data["alias"][0] if "alias" in emoji_data else False text_with_unicode, text_with_placeholder, emoji_list = add_random_emoji(text, qualified_emoji_list, selector) assert emoji.demojize(text_with_unicode, language="alias") == text_with_placeholder assert emoji.emojize(text_with_placeholder, language="alias") == text_with_unicode if not UCS2: assert emoji.replace_emoji(text_with_unicode, u'') == text assert set(emoji.distinct_emoji_list(text_with_unicode)) == set(emoji_list) for i, lis in enumerate(emoji.emoji_list(text_with_unicode)): assert lis['emoji'] == emoji_list[i] # all emoji text_with_unicode, text_with_placeholder, emoji_list = add_random_emoji(text, all_emoji_list) assert emoji.demojize(text_with_unicode) == text_with_placeholder assert clean(emoji.emojize(text_with_placeholder)) == clean(text_with_unicode) if not UCS2: assert emoji.replace_emoji(text_with_unicode, u'') == text assert set(emoji.distinct_emoji_list(text_with_unicode)) == set(emoji_list) for i, lis in enumerate(emoji.emoji_list(text_with_unicode)): assert lis['emoji'] == emoji_list[i]
def remove_emoji(tweet): # Remove emojis return emoji.replace_emoji(tweet, '')