Skip to content

Commit 921e8b4

Browse files
committed
Add a deduped version for use without a suffix
Add an extra space to a keyword if such a keyword also forms a beginning of another keyword, e.g. +1 +1_tone1 This allows entering both without having to define a suffix as this extra space serves the role of a suffix Fixes: #9
1 parent 3c7a121 commit 921e8b4

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Even if the script was written quickly, it is now more useable, and supports I18
1717
3. Set your desired prefix and suffix by right clicking the collection in the snippets view:
1818
1. Edit the collection ![edit.png](manual/edit.png)
1919
2. Set your prefix and suffix ![prefixsuffix.png](manual/prefixsuffix.png)
20+
3. If you don't plan to use a suffix, then download and install the [alternative snippets file](https://github.com/paris-ci/Alfred-Emoji-Pack-Update/raw/master/snippets/Emoji%20Pack%20Update%20Deduped.alfredsnippets) to avoid shorter keywords overriding the longer compound ones (`+1` becomes `+1␣` to allow entering `1_tone1`)
2021
4. Enjoy !

config.py

100644100755
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
languages_to_generate = ["en"] # For now, there is no change between languages, but maybe in the future, shortcodes will be I18N'ed, and the script is ready for that.
22
output_dir = "snippets/"
3-
cache_dir = "cache/" # WARNING : This will get emptied!
4-
enable_skins = True # Use ok_hand_tone1 for example
3+
cache_dir_def = "cache/def/" # WARNING : This will get emptied!
4+
cache_dir_dedupe = "cache/dedupe/" # WARNING : This will get emptied!
5+
enable_skins = True # Use ok_hand_tone1 for example
56

67

78
# == Config test, do not edit after this line. ==
@@ -21,4 +22,5 @@ def ensure_directory(directory, empty=False):
2122

2223
assert set(languages_to_generate).issubset(set(AVAILABLE_LANGS)), "The language specified cound't be found."
2324
ensure_directory(output_dir)
24-
ensure_directory(cache_dir, empty=True)
25+
ensure_directory(cache_dir_def, empty=True)
26+
ensure_directory(cache_dir_dedupe, empty=True)

main.py

100644100755
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def download_shortcodes(language) -> Dict:
2323
file = requests.get(f"https://cdn.jsdelivr.net/npm/emojibase-data@latest/{language}/shortcodes/emojibase.json")
2424
return file.json()
2525

26-
def generate_alfred_snippet_file(key, value):
26+
def generate_alfred_snippet_file(key, value, cache_dir):
2727
uid = str(uuid.uuid4())
2828

2929
content = {
@@ -35,7 +35,7 @@ def generate_alfred_snippet_file(key, value):
3535
}
3636
}
3737
try:
38-
with open(f"{config.cache_dir}/{value} {key} - {uid}.json", "w") as f:
38+
with open(f"{cache_dir}/{value} {key} - {uid}.json", "w") as f:
3939
json.dump(content, f, ensure_ascii=False)
4040
except OSError:
4141
pass
@@ -63,14 +63,24 @@ def main():
6363

6464
for shortcode, emoji in emojis_to_convert.items():
6565
print(f":{shortcode}: -> {emoji}")
66-
generate_alfred_snippet_file(shortcode, emoji)
67-
68-
shutil.copyfile("icon.png", config.cache_dir + "icon.png")
69-
file_name = f"./{config.output_dir}Emoji Pack Update.alfredsnippets"
70-
print(f"Saving to {file_name}")
71-
72-
shutil.make_archive(file_name, "zip", root_dir=config.cache_dir)
73-
os.rename(file_name + ".zip", file_name)
66+
generate_alfred_snippet_file(shortcode, emoji, config.cache_dir_def)
67+
if any((sc.startswith(shortcode) and sc != shortcode) for sc in emojis_to_convert):
68+
shortcode += ' '
69+
print(f":{shortcode}:-> {emoji} (deduped version)")
70+
generate_alfred_snippet_file(shortcode, emoji, config.cache_dir_dedupe)
71+
72+
shutil.copyfile("icon.png", config.cache_dir_def + "icon.png")
73+
shutil.copyfile("icon.png", config.cache_dir_dedupe + "icon.png")
74+
file_name_def = f"./{config.output_dir}Emoji Pack Update.alfredsnippets"
75+
file_name_dedupe = f"./{config.output_dir}Emoji Pack Update Deduped.alfredsnippets"
76+
print(f"Saving to {file_name_def}")
77+
78+
shutil.make_archive(file_name_def, "zip", root_dir=config.cache_dir_def)
79+
os.rename(file_name_def + ".zip", file_name_def)
80+
81+
print(f"Saving to {file_name_dedupe}")
82+
shutil.make_archive(file_name_dedupe, "zip", root_dir=config.cache_dir_dedupe)
83+
os.rename(file_name_dedupe + ".zip", file_name_dedupe)
7484

7585

7686
if __name__ == '__main__':
Binary file not shown.

0 commit comments

Comments
 (0)