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

Merge: Shortcode search #2

Merged
merged 25 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a1bf312
Added a function that retrieves emoji codes
MyriaCore Jul 20, 2020
00f5245
Reformatted create table script
MyriaCore Jul 20, 2020
d6974b3
🚧💡 Added shortcodes to name_search column in spider logic
MyriaCore Jul 20, 2020
9685edd
🚧🎨 Improved readability of sqlite query
MyriaCore Jul 20, 2020
8727e9d
🚧🏗 Added a dedicated shortcodes column in the emojis table
MyriaCore Jul 20, 2020
835589e
🚧✨ Added a new search setting
MyriaCore Jul 20, 2020
8898472
🚧✨ Integrated the new search setting with the main logic
MyriaCore Jul 20, 2020
88df330
🚧🐛 Resolving Bugs with current setup
MyriaCore Jul 20, 2020
ee11208
🚧✨ Made the EmojiSpider printouts a bit prettier
MyriaCore Jul 20, 2020
0ee66a5
🚧🍱 Ran Emoji Spider
MyriaCore Jul 20, 2020
1fc31ad
Prepared DB for structure updates
MyriaCore Jul 21, 2020
b7f436b
🐛 Fixed name encoding bug
MyriaCore Jul 21, 2020
d0d8ac4
🎨 Reformatted main search query to be a bit less awful
MyriaCore Jul 21, 2020
1e8a008
✨🎨 Drafted the extension search logic
MyriaCore Jul 21, 2020
29e5b18
🐛 Fixed enough bugs to make a small version run
MyriaCore Jul 21, 2020
c20f4c5
:fire: Removed break statement (used for debugging)
MyriaCore Jul 21, 2020
85f6dd1
Updated DB w/ spider logic
MyriaCore Jul 21, 2020
e119d35
✨ Emoji list is now better ordered
MyriaCore Jul 22, 2020
a10bc58
🐛 This might fix the skin tone bug
MyriaCore Jul 22, 2020
f8b4f92
🚸 Searching w/ shortcodes now filters shortcodes for the same emoji
MyriaCore Jul 23, 2020
5e67599
🗃 Updated DB with modifier emote data
MyriaCore Jul 23, 2020
c24f37c
🍱 Updated images with modifier emotes
MyriaCore Jul 23, 2020
bdcda22
🔥 Removed shortcode search setting
MyriaCore Jul 23, 2020
44ec152
📝 Added shortcode search screenshot to readme
MyriaCore Jul 23, 2020
acc0244
📝 Made readme a bit more presentable
MyriaCore Jul 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
81 changes: 64 additions & 17 deletions EmojiSpider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import scrapy
import requests
import lxml.html
import sqlite3
import shutil
import base64
Expand All @@ -27,14 +28,31 @@ def cleanup():
def setup_db():
conn = sqlite3.connect('emoji.sqlite', check_same_thread=False)
conn.executescript('''
CREATE TABLE emoji (name VARCHAR PRIMARY KEY, code VARCHAR,
icon_apple VARCHAR, icon_twemoji VARCHAR,
icon_noto VARCHAR, icon_blobmoji VARCHAR,
keywords VARCHAR, name_search VARCHAR);
CREATE TABLE skin_tone (name VARCHAR, code VARCHAR, tone VARCHAR,
icon_apple VARCHAR, icon_twemoji VARCHAR,
icon_noto VARCHAR, icon_blobmoji VARCHAR);
CREATE INDEX name_idx ON skin_tone (name);''')
CREATE TABLE emoji (
name VARCHAR PRIMARY KEY,
code VARCHAR,
icon_apple VARCHAR,
icon_twemoji VARCHAR,
icon_noto VARCHAR,
icon_blobmoji VARCHAR,
keywords VARCHAR,
name_search VARCHAR
);
CREATE TABLE skin_tone (
name VARCHAR,
code VARCHAR,
tone VARCHAR,
icon_apple VARCHAR,
icon_twemoji VARCHAR,
icon_noto VARCHAR,
icon_blobmoji VARCHAR
);
CREATE TABLE shortcode (
name VARCHAR,
code VARCHAR
);
CREATE INDEX name_idx ON skin_tone (name);
''')
conn.row_factory = sqlite3.Row

return conn
Expand Down Expand Up @@ -75,17 +93,36 @@ def codepoint_to_url(codepoint, style):
return 'https://github.com/C1710/blobmoji/raw/master/png/128/emoji_u%s.png' \
% base.replace(' ', '_')

def name_to_shortcodes(shortname):
"""
Given an emoji's CLDR Shortname (e.g. 'grinning face with smiling eyes'), returns a list
of common shortcodes used for that emoji.

NOTE: These shortcodes will NOT have colons at the beginning and end, even if they normally
would.
"""
url = 'https://emojipedia.org/%s/' % re.sub(r'[^a-z0-9 ]', '', shortname.lower()).replace(' ', '-')
response = requests.get(url, stream=True)
response.raw.decode_content = True
html = lxml.html.parse(response.raw) if response.ok else None
shortcode_nodes = html.xpath('//ul[@class="shortcodes"]/li/span[@class="shortcode"]') if html else []
return [s.text for s in shortcode_nodes]

cleanup()
conn = setup_db()

class EmojiSpider(scrapy.Spider):
name = 'emojispider'
start_urls = ['http://unicode.org/emoji/charts/emoji-list.html']
start_urls = ['http://unicode.org/emoji/charts/emoji-list.html',
'http://unicode.org/emoji/charts/full-emoji-modifiers.html']
# start_urls = ['http://172.17.0.1:8000/list2.html']

def parse(self, response):
icon = 0
for tr in response.xpath('//tr[.//td[@class="code"]]'):
emoji_nodes = response.xpath('//tr[.//td[@class="code"]]')
for i in range(0, len(emoji_nodes)):
# Scrape Data from unicode.org
tr = emoji_nodes[i]
code = tr.css('.code a::text').extract_first()
encoded_code = str_to_unicode_emoji(code)
name = ''.join(tr.xpath('(.//td[@class="name"])[1]//text()').extract())
Expand All @@ -98,22 +135,28 @@ def parse(self, response):
if found:
skin_tone = found.group('skin_tone')
name = name.replace(': %s skin tone' % skin_tone, '')
shortcodes = name_to_shortcodes(name)

# Prepare emoji data to be inserted into DB
print("Fetching %i/%i: %s %s" % (i+1, len(emoji_nodes), encoded_code, name))
record = {
'name': name,
'code': encoded_code,
'shortcodes': ' '.join(shortcodes),
'keywords': keywords,
'tone': skin_tone,
'name_search': ' '.join(set(
[kw.strip() for kw in ('%s %s' % (name, keywords)).split(' ')]
[s[1:-1] for s in shortcodes] + [kw.strip() for kw in ('%s %s' % (name, keywords)).split(' ')]
)),
# Icons Styles
# Merge icon styles into record
**{ 'icon_%s' % style: '%s/%s.png' \
% (ICONS_PATH(style), icon_name) \
for style in EMOJI_STYLES \
}
}


# Download Icons for each emoji
print("🖼 Downloading Icons...")
supported_styles = []
for style in EMOJI_STYLES:
if style == 'apple':
Expand All @@ -123,13 +166,14 @@ def parse(self, response):
link = codepoint_to_url(code, style)
resp = requests.get(link)
icon_data = resp.content if resp.ok else None
print('[%s] %s' % ('OK' if resp.ok else 'BAD', link))

print('- %s: %s' % ('' if resp.ok else '', style))
if icon_data:
with open(record['icon_%s' % style], 'wb') as f:
f.write(icon_data)
supported_styles += [style]

# Prepare emoji insertion query
supported_styles = ['icon_%s' % style for style in supported_styles]
if skin_tone:
query = '''INSERT INTO skin_tone (name, code, tone, ''' + ', '.join(supported_styles) + ''')
Expand All @@ -140,8 +184,11 @@ def parse(self, response):
VALUES (:name, :code, ''' + ', '.join([':%s' % s for s in supported_styles]) + ''',
:keywords, :name_search)'''

# Insert emoji & associated shortcodes into DB
conn.execute(query, record)

yield record
for sc in shortcodes:
squery = '''INSERT INTO shortcode (name, code)
VALUES (:name, "%s")''' % sc
conn.execute(squery, record)

conn.commit()
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Emoji Extension

<img aligh="center" src="screenshots/search.png">
<table>
<tr>
<td><img src="screenshots/search.png"></td>
<td><img src="screenshots/shortcode-search.png"></td>
</tr>
</table>

<img aligh="center" src="screenshots/preferences.png">
## Features

### Credits
- Supports Twemoji, Blobmoji, and Noto emoji preview renders
- Search by emoji name, *or* by shortcode by beginning the search with `:`
- Support for multiple skin tones via settings

[twemoji](https://github.com/twitter/twemoji), [noto-emoji](https://github.com/googlefonts/noto-emoji), and [blobmoji](https://github.com/C1710/blobmoji) for emoji styles :heart:.
### Settings

![](screenshots/preferences.png)

## Credits

- [emojipedia.org](https://emojipedia.org/) for emoji shortcode data
- [twemoji](https://github.com/twitter/twemoji), [noto-emoji](https://github.com/googlefonts/noto-emoji), and [blobmoji](https://github.com/C1710/blobmoji) for emoji styles :heart:.
Binary file modified emoji.sqlite
Binary file not shown.
Binary file added images/apple/emoji/Mrs._Claus_dark_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/Mrs._Claus_light_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/OK_hand_dark_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/OK_hand_light_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/OK_hand_medium_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/Santa_Claus_dark_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/artist_dark_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/artist_light_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/artist_medium_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/astronaut_dark_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/astronaut_light_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/astronaut_medium_skin_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/apple/emoji/baby_angel_dark_skin_tone.png
Binary file added images/apple/emoji/baby_angel_light_skin_tone.png
Binary file added images/apple/emoji/baby_dark_skin_tone.png
Binary file added images/apple/emoji/baby_light_skin_tone.png
Binary file added images/apple/emoji/baby_medium-dark_skin_tone.png
Binary file added images/apple/emoji/baby_medium_skin_tone.png
Binary file added images/apple/emoji/boy_dark_skin_tone.png
Binary file added images/apple/emoji/boy_light_skin_tone.png
Binary file added images/apple/emoji/boy_medium-dark_skin_tone.png
Binary file added images/apple/emoji/boy_medium-light_skin_tone.png
Binary file added images/apple/emoji/boy_medium_skin_tone.png
Binary file added images/apple/emoji/call_me_hand_dark_skin_tone.png
Binary file added images/apple/emoji/child_dark_skin_tone.png
Binary file added images/apple/emoji/child_light_skin_tone.png
Binary file added images/apple/emoji/child_medium_skin_tone.png
Binary file added images/apple/emoji/cook_dark_skin_tone.png
Binary file added images/apple/emoji/cook_light_skin_tone.png
Binary file added images/apple/emoji/cook_medium-dark_skin_tone.png
Binary file added images/apple/emoji/cook_medium_skin_tone.png
Binary file added images/apple/emoji/dark_skin_tone.png
Binary file added images/apple/emoji/deaf_man_dark_skin_tone.png
Binary file added images/apple/emoji/deaf_man_light_skin_tone.png
Binary file added images/apple/emoji/deaf_man_medium_skin_tone.png
Binary file added images/apple/emoji/deaf_person_dark_skin_tone.png
Binary file added images/apple/emoji/deaf_woman_dark_skin_tone.png
Binary file added images/apple/emoji/deaf_woman_light_skin_tone.png
Binary file added images/apple/emoji/detective_dark_skin_tone.png
Binary file added images/apple/emoji/detective_light_skin_tone.png
Binary file added images/apple/emoji/detective_medium_skin_tone.png
Binary file added images/apple/emoji/ear_dark_skin_tone.png
Binary file added images/apple/emoji/ear_light_skin_tone.png
Binary file added images/apple/emoji/ear_medium-dark_skin_tone.png
Binary file added images/apple/emoji/ear_medium-light_skin_tone.png
Binary file added images/apple/emoji/ear_medium_skin_tone.png
Binary file added images/apple/emoji/elf_dark_skin_tone.png
Binary file added images/apple/emoji/elf_light_skin_tone.png
Binary file added images/apple/emoji/elf_medium-dark_skin_tone.png
Binary file added images/apple/emoji/elf_medium-light_skin_tone.png
Binary file added images/apple/emoji/elf_medium_skin_tone.png
Binary file added images/apple/emoji/fairy_dark_skin_tone.png
Binary file added images/apple/emoji/fairy_light_skin_tone.png
Binary file added images/apple/emoji/fairy_medium_skin_tone.png
Binary file added images/apple/emoji/farmer_dark_skin_tone.png
Binary file added images/apple/emoji/farmer_light_skin_tone.png
Binary file added images/apple/emoji/farmer_medium_skin_tone.png
Binary file added images/apple/emoji/firefighter_dark_skin_tone.png
Binary file added images/apple/emoji/flexed_biceps_dark_skin_tone.png
Binary file added images/apple/emoji/foot_dark_skin_tone.png
Binary file added images/apple/emoji/foot_light_skin_tone.png
Binary file added images/apple/emoji/foot_medium-dark_skin_tone.png
Binary file added images/apple/emoji/foot_medium_skin_tone.png
Binary file added images/apple/emoji/girl_dark_skin_tone.png
Binary file added images/apple/emoji/girl_light_skin_tone.png
Binary file added images/apple/emoji/girl_medium-dark_skin_tone.png
Binary file added images/apple/emoji/girl_medium_skin_tone.png
Binary file added images/apple/emoji/guard_dark_skin_tone.png
Binary file added images/apple/emoji/guard_light_skin_tone.png
Binary file added images/apple/emoji/guard_medium_skin_tone.png
Binary file added images/apple/emoji/judge_dark_skin_tone.png
Binary file added images/apple/emoji/judge_light_skin_tone.png
Binary file added images/apple/emoji/judge_medium_skin_tone.png
Binary file added images/apple/emoji/leg_dark_skin_tone.png
Binary file added images/apple/emoji/leg_light_skin_tone.png
Binary file added images/apple/emoji/leg_medium-dark_skin_tone.png
Binary file added images/apple/emoji/leg_medium-light_skin_tone.png
Binary file added images/apple/emoji/leg_medium_skin_tone.png
Binary file added images/apple/emoji/light_skin_tone.png
Binary file added images/apple/emoji/mage_dark_skin_tone.png
Binary file added images/apple/emoji/mage_light_skin_tone.png
Binary file added images/apple/emoji/mage_medium-dark_skin_tone.png
Binary file added images/apple/emoji/mage_medium_skin_tone.png
Binary file added images/apple/emoji/man_artist_dark_skin_tone.png
Binary file added images/apple/emoji/man_artist_light_skin_tone.png
Binary file added images/apple/emoji/man_biking_dark_skin_tone.png
Binary file added images/apple/emoji/man_biking_light_skin_tone.png
Binary file added images/apple/emoji/man_bowing_dark_skin_tone.png
Binary file added images/apple/emoji/man_bowing_light_skin_tone.png
Binary file added images/apple/emoji/man_cook_dark_skin_tone.png
Binary file added images/apple/emoji/man_cook_light_skin_tone.png
Binary file added images/apple/emoji/man_cook_medium_skin_tone.png
Binary file added images/apple/emoji/man_dancing_dark_skin_tone.png
Binary file added images/apple/emoji/man_dark_skin_tone,_bald.png
Binary file added images/apple/emoji/man_dark_skin_tone,_beard.png
Binary file added images/apple/emoji/man_dark_skin_tone.png
Binary file added images/apple/emoji/man_elf_dark_skin_tone.png
Binary file added images/apple/emoji/man_elf_light_skin_tone.png
Binary file added images/apple/emoji/man_elf_medium_skin_tone.png
Loading