Skip to content

Commit

Permalink
Added distutils infrastructure.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Aug 6, 2016
1 parent 191b755 commit 74a890c
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 71 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.pyc
__pycache__
*~
.*.sw[op]
*.egg-info
*.egg
.eggs
.tox
local
dist
build
_build
distribute-*
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include *.rst
include LICENSE
recursive-include tests *.py
recursive-include docs Makefile
recursive-include docs *.py
recursive-include docs *.bat
recursive-include docs *.rst
33 changes: 0 additions & 33 deletions README.md

This file was deleted.

34 changes: 34 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
emojificate
===========

Emojificate is a Python implementation of a concept of using fallback images, alt text, title text and aria labels to represent emoji in HTML code in a more accessible method.

Usage
-----

To convert a string::

$ python3 -m emojificate "I 💜 emoji 😊"
I <img src="https://twemoji.maxcdn.com/36x36/1f49c.png" alt="💜" title="Purple Heart" height="16px" aria-label="Emoji: Purple Heart"> emoji <img src="https://twemoji.maxcdn.com/36x36/1f60a.png" alt="😊" title="Smiling Face With Smiling Eyes" height="16px" aria-label="Emoji: Smiling Face With Smiling Eyes">

Implementation
--------------

TL;DR: Take a string, split it into token, and if a token is emoji, process it into a nice format.

Using `uniseq's <http://uniseg-python.readthedocs.io/en/latest/graphemecluster.html#uniseg.graphemecluster.grapheme_clusters>`__ implementation of the `Unicode Text Segmentation <http://www.unicode.org/reports/tr29/tr29-21.html>`__ standard, we can split a string into separate tokens.

Leveraging the native `unicodedata <https://docs.python.org/3/library/unicodedata.html>`__ we can:

* see if a token is a unicode Symbol (an emoji)
* get the codepoint for the emoji, and
* get the name of the emoji

From there, we construct an ``<img>`` replacement for the emoji:

* Use images from `twemoji <https://github.com/twitter/twemoji>`__, Twitter's emoji set
* Have an ``alt`` parameter containing the original emoji. This allows for copying-pasting.
* Use the name of the emoji in the ``title`` parameter. This allows for hover-tooltips.
* Add an ``aria-label`` for screen-reader accessibility.

For more information, see `Solve For Emoji <http://glasnt.com/blog/2016/08/06/solve-for-emoji.html>`__.
38 changes: 0 additions & 38 deletions emojificate.py

This file was deleted.

9 changes: 9 additions & 0 deletions emojificate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Examples of valid version strings
# __version__ = '1.2.3.dev1' # Development release 1
# __version__ = '1.2.3a1' # Alpha Release 1
# __version__ = '1.2.3b1' # Beta Release 1
# __version__ = '1.2.3rc1' # RC Release 1
# __version__ = '1.2.3' # Final Release
# __version__ = '1.2.3.post1' # Post Release 1

__version__ = "0.1.0"
16 changes: 16 additions & 0 deletions emojificate/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys

from .filter import emojificate


def display_help():
print("emojificate.py -- turns text with emoji into text with accessible emoji")


if __name__ == "__main__":
line = " ".join(sys.argv[1:])
if line:
print(emojificate(line))
else:
display_help()
sys.exit(1)
34 changes: 34 additions & 0 deletions emojificate/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unicodedata
from uniseg import graphemecluster as gc


__all__ = ['emojificate']


cdn = "https://twemoji.maxcdn.com/36x36/"
cdn_ft = ".png"


def tag(a, b):
return "%s=\"%s\"" % (a, b)


def emojificate(line):
result = ""

for char in gc.grapheme_clusters(line):
append = char
if unicodedata.category(char) == "So":
name = unicodedata.name(char).title()
code = char.encode("unicode_escape").decode("utf-8")[2:].strip("0")
append = "".join([
"<img",
tag(" src", cdn + code + cdn_ft),
tag(" alt", char),
tag(" title", name),
tag(" aria-label", "Emoji: %s" % name),
">"
])

result += append
return result
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal=1
44 changes: 44 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import re
from setuptools import setup, find_packages
from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

# Get the long description from the relevant file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()

with open(path.join(here, 'emojificate', '__init__.py'), encoding='utf8') as version_file:
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file.read(), re.M)
if version_match:
version = version_match.group(1)
else:
raise RuntimeError("Unable to find version string.")

setup(
name='emojificate',
version=version,
description='A Python implementation of a concept of using fallback images, alt text, title text and aria labels to represent emoji in HTML code in a more accessible method.',
long_description=long_description,
url='https://github.com/glasnt/emojificate',
author='Katie McLaughlin',
author_email='[email protected]',
license='New BSD',
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Text Processing :: Filters',
'Topic :: Utilities',
],
keywords='emoji accessibility a11y',
packages=find_packages(exclude=['docs', 'test']),
install_requires=['uniseg']
)

0 comments on commit 74a890c

Please sign in to comment.