Skip to content

Commit

Permalink
Python3 support ✨ 🐍 ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
bcongdon committed Feb 6, 2017
1 parent 7461c46 commit 790d396
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ target/
.ipynb_checkpoints
venv
.env
venv3
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ language: python
python:
- "2.6"
- "2.7"
- "3.5"
- "3.6"
install:
- "pip install -r requirements.txt"
script: nosetests
script: nosetests
2 changes: 1 addition & 1 deletion emojipedia/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from emojipedia import Emojipedia
from .emojipedia import Emojipedia
2 changes: 1 addition & 1 deletion emojipedia/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __str__(self):
string = string.format(self.title,
self.description[:20] + "...",
self.character)
return string.encode('utf-8')
return string

def __repr__(self):
return self.__str__()
7 changes: 4 additions & 3 deletions emojipedia/emojipedia.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import unicode_literals
from bs4 import BeautifulSoup
import requests
from emoji import Emoji
from codecs import decode
from .emoji import Emoji


class Emojipedia:
Expand All @@ -23,12 +24,12 @@ def valid_emoji_page(soup):

@staticmethod
def get_emoji_page(query):
response = requests.get('http://emojipedia.org/' + query.decode('utf-8', 'backslashreplace'))
response = requests.get('http://emojipedia.org/' + query)
if response.status_code != 200:
raise UserWarning('Could not get emojipedia page for \'{0}\''
.format(query))

soup = BeautifulSoup(response.text)
soup = BeautifulSoup(response.text, 'html.parser')
if not Emojipedia.valid_emoji_page(soup):
raise UserWarning('Query did not yield a emoji entry')
return soup
9 changes: 7 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
beautifulsoup4==4.3.2
requests==2.5.0
appdirs==1.4.0
beautifulsoup4==4.4.0
nose==1.3.7
packaging==16.8
pyparsing==2.1.10
requests==2.5.0
six==1.10.0
11 changes: 7 additions & 4 deletions test_emojipedia.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from emojipedia import Emojipedia
import nose.tools

Expand Down Expand Up @@ -70,11 +72,12 @@ def test_emoji_title():

def test_emoji_character():
taco = Emojipedia.search('taco')
# Python Unicode silliness
assert taco.character.encode('unicode_escape') == '\\U0001f32e'
assert taco.character == u'🌮'


def test_emoji_repr():
pizza = Emojipedia.search('slice-of-pizza')
found = str(pizza).decode('utf-8').encode('ascii', 'backslashreplace')
assert found.startswith('<Emoji - ') and found.endswith('>')
correct = u"<Emoji - 'Pizza' - character: 🍕, description: A slice  of pizza, w...>"
print(type(correct))
print(type(pizza.__str__()))
assert pizza.__str__() == correct

0 comments on commit 790d396

Please sign in to comment.