From 94cf63257dab77ffd4776da827aa6d77ab041db3 Mon Sep 17 00:00:00 2001 From: Paul Hendrick Date: Sat, 17 Mar 2018 14:18:02 -0400 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Implement=20matching=20icons=20?= =?UTF-8?q?for=20each=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This workflow presents a list of emoji, so naturally the icon for each list item would be that emoji. Problem is, Alfred only supports files for this. What we can do is grab the pngs we need from EmojiOne. I'm having them written to the data directory, which seems better than just packaging them in the workflow? --- gitmoji.py | 17 ++++++++++++++--- info.plist | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gitmoji.py b/gitmoji.py index 9dc8bb0..833780f 100755 --- a/gitmoji.py +++ b/gitmoji.py @@ -1,12 +1,12 @@ #!/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() @@ -16,11 +16,22 @@ def main(wf): data = wf.cached_data('gitmoji_db', get_gitmoji_db, max_age=86400) for emoji in data['gitmojis']: + unicode = emoji['emoji'] + str = unicode.encode('unicode-escape') + if str.startswith('\U000'): + id = str[5:] + elif str.startswith('\u'): + id = str.split('\u')[1] + icon = wf.datafile(id + '.png') + if not os.path.isfile(icon): + request = web.get(emojione_assets + '/' + id + '.png') + request.save_to_path(icon) + wf.add_item( title=emoji['emoji'] + ' ' + emoji['code'], subtitle=emoji['description'], valid=True, - icon='9B7FE8AC-6582-4825-917E-92D0E0291CC1.png', + icon=icon, 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 From e62f0ba4ab6b805345ae1e489af57e0bfcb4f6cb Mon Sep 17 00:00:00 2001 From: Paul Hendrick Date: Sat, 23 Feb 2019 17:02:45 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20=20Address=20issue=20with=20?= =?UTF-8?q?Label=20emoji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new gitmoji for "Adding or updating types" introduces a new case where the emoji being used decodes to a combination of \U and \u escaped codes (4 hex and 8 hex respectively), so the logic needs to improve in order to correctly resolve to the filename used by emojione-assets. --- gitmoji.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gitmoji.py b/gitmoji.py index 833780f..a881cba 100755 --- a/gitmoji.py +++ b/gitmoji.py @@ -7,6 +7,7 @@ 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() @@ -16,15 +17,15 @@ def main(wf): data = wf.cached_data('gitmoji_db', get_gitmoji_db, max_age=86400) for emoji in data['gitmojis']: - unicode = emoji['emoji'] - str = unicode.encode('unicode-escape') - if str.startswith('\U000'): - id = str[5:] - elif str.startswith('\u'): - id = str.split('\u')[1] - icon = wf.datafile(id + '.png') + 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 + '/' + id + '.png') + request = web.get(emojione_assets + '/' + filename + '.png') request.save_to_path(icon) wf.add_item( From b7ef202b70bf0824afd95405bae289af7f4949d7 Mon Sep 17 00:00:00 2001 From: Paul Hendrick Date: Sat, 23 Feb 2019 20:11:51 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20readability=20of?= =?UTF-8?q?=20icons=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gitmoji.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/gitmoji.py b/gitmoji.py index a881cba..3839a2b 100755 --- a/gitmoji.py +++ b/gitmoji.py @@ -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'],