Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
🎨 Improve readability of icons feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pghk committed Feb 24, 2019
1 parent e62f0ba commit b7ef202
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions gitmoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,35 @@

gitmoji_db = 'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json'
emojione_assets = 'https://raw.githubusercontent.com/emojione/emojione-assets/master/png/128'
esc_seqs = {'\\U000': ' ', '\\u': ' '}

def get_gitmoji_db():
return web.get(gitmoji_db).json()

def determine_icon_name(emoji):
esc_seqs = ['\\U000', '\\u']
ascii_char = emoji.encode('unicode-escape')
codes = ascii_char
for x in esc_seqs:
codes = codes.replace(x, " ")
return codes.split()[0] + ".png"

def fetch_icon(wf, emoji):
filename = determine_icon_name(emoji)
icon = wf.datafile(filename)
if not os.path.isfile(icon):
request = web.get(emojione_assets + '/' + filename)
request.save_to_path(icon)
return icon

def main(wf):
data = wf.cached_data('gitmoji_db', get_gitmoji_db, max_age=86400)

for emoji in data['gitmojis']:
unicode_emoji = emoji['emoji']
ascii_emoji = unicode_emoji.encode('unicode-escape')
for r,s in esc_seqs.items():
ascii_emoji = ascii_emoji.replace(r,s)
codes = ascii_emoji.split()
filename = codes[0]
icon = wf.datafile(filename + '.png')
if not os.path.isfile(icon):
request = web.get(emojione_assets + '/' + filename + '.png')
request.save_to_path(icon)

wf.add_item(
title=emoji['emoji'] + ' ' + emoji['code'],
subtitle=emoji['description'],
valid=True,
icon=icon,
icon=fetch_icon(wf, emoji['emoji']),
match=emoji['name'] + ' ' + emoji['description'],
arg=emoji['code'],
copytext=emoji['code'],
Expand Down

0 comments on commit b7ef202

Please sign in to comment.