diff --git a/gitmoji.py b/gitmoji.py index 9dc8bb0..3839a2b 100755 --- a/gitmoji.py +++ b/gitmoji.py @@ -1,16 +1,31 @@ #!/usr/bin/python # encoding: utf-8 -import sys +import sys, os from workflow import Workflow3, web 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' 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) @@ -20,7 +35,7 @@ def main(wf): title=emoji['emoji'] + ' ' + emoji['code'], subtitle=emoji['description'], valid=True, - icon='9B7FE8AC-6582-4825-917E-92D0E0291CC1.png', + icon=fetch_icon(wf, emoji['emoji']), match=emoji['name'] + ' ' + emoji['description'], arg=emoji['code'], copytext=emoji['code'], diff --git a/info.plist b/info.plist index 04c743f..b4b95aa 100644 --- a/info.plist +++ b/info.plist @@ -70,7 +70,7 @@ queuemode 1 runningsubtext - + getting icons... script chmod +x jq && 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}}]}' scriptargtype