Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work backwards: \U0001f382 to 🎂 #34

Closed
controversial opened this issue Dec 8, 2015 · 6 comments
Closed

Work backwards: \U0001f382 to 🎂 #34

controversial opened this issue Dec 8, 2015 · 6 comments

Comments

@controversial
Copy link

Is it possible for this library to work backwards? Example:

u"\U0001F382" would change to 🎂

@geowurster
Copy link
Collaborator

@The-Penultimate-Defenestrator Yep, it already does that:

>>> import emoji
>>> print(emoji.emojize(u"Happy \U0001F382"))
Happy 🎂

Is that not what you had in mind?

@controversial
Copy link
Author

Yes, I wasn't aware it works both ways, and it wasn't in the README. Thanks.

@geowurster
Copy link
Collaborator

@The-Penultimate-Defenestrator Now that I look at this again, I led you somewhat astray. This works, but the emoji library isn't actually doing anything - your computer is rendering the unicode code as an emoji icon. All emoji.emojize() does is translate :emoji: strings to unicode codes, but in this case the string already contains a unicode code.

For instance:

print(u"\U0001F382")
🎂
$ echo "\U0001F382"
🎂

@controversial
Copy link
Author

Right. I already have a Unicode string. I need to convert the Unicode string to the emoji code because I am using it with the Discord APi

@controversial controversial reopened this Dec 9, 2015
@geowurster
Copy link
Collaborator

@The-Penultimate-Defenestrator Ah I get it - I was confused by the actual icon in the ticket header. If you wrap the text in backticks, like :birthday:, then GitHub won't render the string as an icon.

Yes, this is supported:

import emoji

print(emoji.demojize(u"Happy \U0001F382!"))
Happy :birthday_cake:!

One note is that the :birthday: emoji is actually an alias for :birthday_cake:. You can do emoji.emojize(":birthday_cake:") OR emoji.emojize(":birthday:", use_aliases=True), but emoji.demojize() does not use aliases. The reason is that there are multiple aliases mapped to the same unicode code, so its impossible to know which alias the user wants and returning the official string is more likely to work.

@controversial
Copy link
Author

Thanks. Demojize is what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants