Skip to content

Instantly share code, notes, and snippets.

@Proteusiq
Created July 11, 2018 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Proteusiq/dbf45b2dce4141d8c3b9b12383dde525 to your computer and use it in GitHub Desktop.
Save Proteusiq/dbf45b2dce4141d8c3b9b12383dde525 to your computer and use it in GitHub Desktop.
emojipy.py
import re
from collections import Counter
# eyes [nose] mouth | mouth [nose] eyes pattern
emoticons = r"(?:[<>]?[:;=8][\-o\*\']?[\)\]\(\[dDpP/\:\}\{@\|\\]|[\)\]\(\[dDpP/\:\}\{@\|\\][\-o\*\']?[:;=8][<>]?)"
emoticon_re = re.compile(emoticons, re.VERBOSE | re.I | re.UNICODE)
def has_emoji(texts,get_emoji=False):
set_emoji = set(emoticon_re.findall(texts))
for text in texts.split():
if text in set_emoji:
if get_emoji:
return set_emoji
else:
return True
return False
def count_emoji(texts):
seen_emoji = emoticon_re.findall(texts)
if seen_emoji:
return Counter(seen_emoji)
else:
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment