Skip to content

Commit 790d396

Browse files
committed
Python3 support ✨ 🐍 ✨
1 parent 7461c46 commit 790d396

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ target/
6262
.ipynb_checkpoints
6363
venv
6464
.env
65+
venv3

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: python
22
python:
33
- "2.6"
44
- "2.7"
5+
- "3.5"
6+
- "3.6"
57
install:
68
- "pip install -r requirements.txt"
7-
script: nosetests
9+
script: nosetests

emojipedia/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from emojipedia import Emojipedia
1+
from .emojipedia import Emojipedia

emojipedia/emoji.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __str__(self):
8585
string = string.format(self.title,
8686
self.description[:20] + "...",
8787
self.character)
88-
return string.encode('utf-8')
88+
return string
8989

9090
def __repr__(self):
9191
return self.__str__()

emojipedia/emojipedia.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import unicode_literals
22
from bs4 import BeautifulSoup
33
import requests
4-
from emoji import Emoji
4+
from codecs import decode
5+
from .emoji import Emoji
56

67

78
class Emojipedia:
@@ -23,12 +24,12 @@ def valid_emoji_page(soup):
2324

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

31-
soup = BeautifulSoup(response.text)
32+
soup = BeautifulSoup(response.text, 'html.parser')
3233
if not Emojipedia.valid_emoji_page(soup):
3334
raise UserWarning('Query did not yield a emoji entry')
3435
return soup

requirements.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
beautifulsoup4==4.3.2
2-
requests==2.5.0
1+
appdirs==1.4.0
2+
beautifulsoup4==4.4.0
3+
nose==1.3.7
4+
packaging==16.8
5+
pyparsing==2.1.10
6+
requests==2.5.0
7+
six==1.10.0

test_emojipedia.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
from emojipedia import Emojipedia
24
import nose.tools
35

@@ -70,11 +72,12 @@ def test_emoji_title():
7072

7173
def test_emoji_character():
7274
taco = Emojipedia.search('taco')
73-
# Python Unicode silliness
74-
assert taco.character.encode('unicode_escape') == '\\U0001f32e'
75+
assert taco.character == u'🌮'
7576

7677

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

0 commit comments

Comments
 (0)