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

Commit d6244fe

Browse files
authored
Merge pull request #3 from pghk/feature/icons
✨ Replace item icons with EmojiOne PNGs
2 parents 2a5ad12 + b7ef202 commit d6244fe

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

gitmoji.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
#!/usr/bin/python
22
# encoding: utf-8
33

4-
import sys
4+
import sys, os
55

66
from workflow import Workflow3, web
77

88
gitmoji_db = 'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json'
9-
9+
emojione_assets = 'https://raw.githubusercontent.com/emojione/emojione-assets/master/png/128'
1010

1111
def get_gitmoji_db():
1212
return web.get(gitmoji_db).json()
1313

14+
def determine_icon_name(emoji):
15+
esc_seqs = ['\\U000', '\\u']
16+
ascii_char = emoji.encode('unicode-escape')
17+
codes = ascii_char
18+
for x in esc_seqs:
19+
codes = codes.replace(x, " ")
20+
return codes.split()[0] + ".png"
21+
22+
def fetch_icon(wf, emoji):
23+
filename = determine_icon_name(emoji)
24+
icon = wf.datafile(filename)
25+
if not os.path.isfile(icon):
26+
request = web.get(emojione_assets + '/' + filename)
27+
request.save_to_path(icon)
28+
return icon
1429

1530
def main(wf):
1631
data = wf.cached_data('gitmoji_db', get_gitmoji_db, max_age=86400)
@@ -20,7 +35,7 @@ def main(wf):
2035
title=emoji['emoji'] + ' ' + emoji['code'],
2136
subtitle=emoji['description'],
2237
valid=True,
23-
icon='9B7FE8AC-6582-4825-917E-92D0E0291CC1.png',
38+
icon=fetch_icon(wf, emoji['emoji']),
2439
match=emoji['name'] + ' ' + emoji['description'],
2540
arg=emoji['code'],
2641
copytext=emoji['code'],

info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<key>queuemode</key>
7171
<integer>1</integer>
7272
<key>runningsubtext</key>
73-
<string></string>
73+
<string>getting icons...</string>
7474
<key>script</key>
7575
<string>chmod +x jq &amp;&amp; cat gitmojis.json | ./jq --raw-output '{items: [.gitmojis | .[] | {emoji: .emoji, code: .code, title: (.emoji + " " + .code), subtitle: .description, match: (.description + " " + .name), arg: .code, text: {copy: .code, largetype: .code}}]}'</string>
7676
<key>scriptargtype</key>

0 commit comments

Comments
 (0)