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

v1.0.0 #2

Merged
merged 10 commits into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
emotlib/__version__.py
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: python
python:
- "2.7"
install:
- pip install coveralls pytest-cov
script:
- pytest --cov-report term-missing --cov=emotlib
after_success:
- coveralls
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
# emotlib: Python emoji + emoticon Library

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/emotlib.svg)](https://pypi.org/project/emotlib/)
[![PyPI](https://img.shields.io/pypi/v/emotlib.svg)](https://pypi.org/project/emotlib/)
[![Travis branch](https://img.shields.io/travis/steven5538/emotlib/master.svg)](https://travis-ci.org/steven5538/emotlib)
[![Coveralls github](https://img.shields.io/coveralls/github/steven5538/emotlib.svg)](https://coveralls.io/github/steven5538/emotlib)
[![Read the Docs](https://img.shields.io/readthedocs/emotlib.svg)](http://emotlib.readthedocs.io/en/latest/)
![PyPI - License](https://img.shields.io/pypi/l/emotlib.svg)

Installation
------------

To install emotlib, simply use [pipenv](http://pipenv.org/) (or pip, of course):
```
$ pipenv install emotlib
🍿🍿🎉
🍩🎉
```
Satisfaction guaranteed.

Documentation
Example
-------------

Documentation is available at https://github.com/steven5538/emotlib, for a limited time only.
Note: In python2.x, your string need to be unicode. Ex: u'I\'m :elf:'
``` python
>> import emotlib
>> print(emotlib.emoji())
🧙‍
>> print(emotlib.emoji(category='food-fruit'))
🍉
>> print(emotlib.emoji(num=3))
👨‍🚀👨‍🚀👨‍🚀
>> print(emotlib.emoji(num=3, sep= ' ~ '))
🤸 ~ 🤸 ~ 🤸 ~
>> print(emotlib.emojify('I\'m :man_technologist:'))
I'm 👨‍💻
>> print(emotlib.emojify('I\'m :man~technologist:', alias='~'))
I'm 👨‍💻
>> print(emotlib.demojify('I\'m 👨‍💻'))
I'm :man_technologist:
>> print(emotlib.demojify('I\'m 👨‍💻', alias='~'))
I'm :man~technologist:


>> print(emotlib.emoticon())
( ´ ▽ ` )ノ
>> print(emotlib.emoticon(feel='confused'))
(´−`) ンー
>> print(emotlib.emoticon(num=3))
┌(★o☆)┘┌(★o☆)┘┌(★o☆)┘
>> print(emotlib.emoticon(num=3, sep=' ~ '))
(´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~
>> print(emotlib.emoticonify('I\'m a happy developer.'))
I'm a happy developer. *(*´∀`*)☆
```

Check categories & feels
```python
>> import emotlib
>> emotlib.emoji_categories
>> emotlib.emoticon_feels
```
61 changes: 61 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# emotlib: Python emoji + emoticon Library

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/emotlib.svg)](https://pypi.org/project/emotlib/)
[![PyPI](https://img.shields.io/pypi/v/emotlib.svg)](https://pypi.org/project/emotlib/)
[![Travis branch](https://img.shields.io/travis/steven5538/emotlib/master.svg)](https://travis-ci.org/steven5538/emotlib)
[![Coveralls github](https://img.shields.io/coveralls/github/steven5538/emotlib.svg)](https://coveralls.io/github/steven5538/emotlib)
[![Read the Docs](https://img.shields.io/readthedocs/emotlib.svg)](http://emotlib.readthedocs.io/en/latest/)
![PyPI - License](https://img.shields.io/pypi/l/emotlib.svg)

Installation
------------

To install emotlib, simply use [pipenv](http://pipenv.org/) (or pip, of course):
```
$ pipenv install emotlib
🍩🎉
```
Satisfaction guaranteed.

Example
-------------

Note: In python2.x, your string need to be unicode. Ex: u'I\'m :elf:'
``` python
>> import emotlib
>> print(emotlib.emoji())
🧙‍
>> print(emotlib.emoji(category='food-fruit'))
🍉
>> print(emotlib.emoji(num=3))
👨‍🚀👨‍🚀👨‍🚀
>> print(emotlib.emoji(num=3, sep= ' ~ '))
🤸 ~ 🤸 ~ 🤸 ~
>> print(emotlib.emojify('I\'m :man_technologist:'))
I'm 👨‍💻
>> print(emotlib.emojify('I\'m :man~technologist:', alias='~'))
I'm 👨‍💻
>> print(emotlib.demojify('I\'m 👨‍💻'))
I'm :man_technologist:
>> print(emotlib.demojify('I\'m 👨‍💻', alias='~'))
I'm :man~technologist:


>> print(emotlib.emoticon())
( ´ ▽ ` )ノ
>> print(emotlib.emoticon(feel='confused'))
(´−`) ンー
>> print(emotlib.emoticon(num=3))
┌(★o☆)┘┌(★o☆)┘┌(★o☆)┘
>> print(emotlib.emoticon(num=3, sep=' ~ '))
(´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~
>> print(emotlib.emoticonify('I\'m a happy developer.'))
I'm a happy developer. *(*´∀`*)☆
```

Check categories & feels
```python
>> import emotlib
>> emotlib.emoji_categories
>> emotlib.emoticon_feels
```
127 changes: 127 additions & 0 deletions emotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-

# ('・ω・')

"""
Emoji + Emoticon Library
~~~~~~~~~~~~~~~~~~~~~~~~

emotlib is a library for Emoji and Emoticon, written in Python.
usage:

>>> import emotlib
>>> print(emotlib.emoji())
👨‍🚀
>>> print(emotlib.emoji(num=3))
🧙‍🧙‍🧙‍
>>> print(emotlib.emoticon())
( ´△`)
>>> print(emotlib.emoticon(num=5, sep=' ~ '))
(´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~ (´∇ノ`*)ノ ~

Full documentation at <http://github.com/steven5538/emotlib>.

:copyright: (c) 2018 by steven5538.
:license MIT License, see LICENSE for more details.
"""

from random import choice
import re

from .emoji_unicode_map import *
from .emoticon_unicode_map import *


_EMOJI_REGEX_CACHE = None
emoji_categories = EMOJI_CATEGORIES
emoticon_feels = EMOTICON_FEELS


def _multiple(emo, num=1, sep=''):
num = 1 if num <= 1 else num
sep = '' if num <= 1 else sep
duplicate_unit = '%s%s' % (emo, sep)
return duplicate_unit * num


def decorateMultiple(f):
def wrapper(*args, **kargs):
result = f(*args, **kargs)
num = kargs.get('num', 1)
seperator = kargs.get('sep', '')
return _multiple(result, num, seperator)
return wrapper


@decorateMultiple
def emoticon(feel='', num=1, sep=''):
if feel and feel.lower() in EMOTICON_FEELS:
return choice(EMOTICON_UNICODE[feel.lower()])
return choice(EMOTICONS)


def emoticonify(text):
"""Add feeling emoticon to the end of text.

>>> import emotlib
>>> emotlib.emoticonify('I\'m a happy developer.')
I'm a happy developer. (ᅌᴗᅌ* )
"""

return text + ' ' + ''.join([choice(EMOTICON_UNICODE.get(t, [''])) for t in text.split()])


@decorateMultiple
def emoji(category='', num=1, sep=''):
if category and category.lower() in EMOJI_CATEGORIES:
return choice(list(EMOJI_UNICODE[category.lower()].values()))
return choice(EMOJIS)


def emojify(text, alias='_'):
"""Replace CLDR to emoji. Use to show.
Default alias "_".

>>> import emotlib
>>> emotlib.emojify('I\'m :man_technologist:')
I'm 👨‍💻
>>> emotlib.emojify('I\'m :man~technologist:', alias='~')
I'm 👨‍💻
"""

pattern = re.compile(u'(:[%sa-zA-Z0-9&.()!$_ ]*:)' % alias)

def repl(match):
val = match.group(1)[1:-1].replace(alias, ' ')
return EMOJI_UNICODE_WITHOUT_CATEGORY.get(val, val)

return pattern.sub(repl, text)


def demojify(text, alias='_'):
"""Replace emoji to CLDR. Useful if you need to store.
Default alias "_".

>>> import emotlib
>>> emotlib.demojify('I\'m 👨‍💻')
I'm :man_technologist:
>>> emotlib.demojify('I\'m 👨‍💻', alias='~')
I'm :man~technologist:
"""

def repl(match):
val = UNICODE_EMOJI_WITHOUT_CATEGORY.get(match.group(0), match.group(0))
return ':' + alias.join(val[:].split()) + ':'

return _emoji_regex_cache().sub(repl, text)


def _emoji_regex_cache():
global _EMOJI_REGEX_CACHE

if _EMOJI_REGEX_CACHE is None:
emojis = sorted(EMOJIS, key=len, reverse=True)
pattern = u'(' + u'|'.join(re.escape(u) for u in emojis) + u')'
_EMOJI_REGEX_CACHE = re.compile(pattern)

return _EMOJI_REGEX_CACHE
2 changes: 1 addition & 1 deletion emotlib/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__title__ = 'emotlib'
__description__ = 'Python emoji + emoticon Library'
__url__ = 'https://github.com/steven5538/emotlib'
__version__ = '0.0.2'
__version__ = '1.0.0'
__author__ = 'steven5538'
__author_email__ = 'steven5538@gmail.com'
__license__ = 'MIT License'
Expand Down
Loading