Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert emoji unicode to TEXT in python

Tags:

python

emoji

I have an application made in python (yowsup), I receive text and emoji in my bot... I manage to get the 😀 to convert to "\U0001F600" code...

now i need to convert u"\U0001F600" to :grinning: TEXT or GRINNING FACE

got some source from this page.... http://www.fileformat.info/info/unicode/char/1F600/index.htm

@signals.message_received.connect
def handle(message):
    #message.log() to see message object properties
    #print(message.log())
    params = {}
    params_upload = {}
    zapsend_host = config.config_variables['zapsend_host']
    zapsend_port = config.config_variables['zapsend_port']

    # CASE TEXT-MESSAGE AND NOT GROUP
    if helper.is_text_message(message.message_entity) and helper.isGroupJid(message.conversation) == False:
        #converted here....
        params['msg']  = message.text.encode('unicode_escape') 
        params['number']  = message.conversation
        params['whatsapp']= config.config_variables['user']
        params['media'] = 'text'
        params['caption'] = ''
        params['name'] = message.who_name
        database_helper.sync_contacts(message.conversation, message.who_name)
        database_helper.save_message_receive(params, message)
        print("MSG FROM CLIENT: "+ message.conversation +" => " + params['msg'])
        requests_helper.request_get(zapsend_host, zapsend_port,'zapsend',params)
like image 747
sealabr Avatar asked Dec 01 '22 11:12

sealabr


2 Answers

@sealabr check this.

import emoji
print(emoji.demojize('Python is 👍'))
>>Python is :thumbs_up:
like image 189
Muhammad Younus Avatar answered Dec 04 '22 08:12

Muhammad Younus


Try this:

s = u'\U0001f600'
from emoji.unicode_codes import UNICODE_EMOJI

print UNICODE_EMOJI[s]
>:grinning_face:

this assumes you have the module emoji installed

like image 28
Simon Mengong Avatar answered Dec 04 '22 09:12

Simon Mengong