Skip to content

Commit a9886c1

Browse files
committed
release: v1.0.0
- launch of the app - local api - plenty of languages - emojipedia links
1 parent e548101 commit a9886c1

File tree

115 files changed

+18218
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+18218
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Benjamin Oddou
3+
Copyright (c) 2023-present Benjamin Oddou
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<img src="public/icon_dark_mode.webp#gh-dark-mode-only" alt="logo-dark" height="55"/>
2+
<img src="public/icon_light_mode.webp#gh-light-mode-only" alt="logo-light" height="55"/>
3+
4+
[![made with heart by Benjamin Oddou](https://img.shields.io/badge/made%20with%20%E2%99%A5%20by-benjamin%20oddou-ff2f35.svg?style=flat)](https://github.com/BenjaminOddou)
5+
[![saythanks](https://img.shields.io/badge/say-thanks-bf0001.svg?style=flat)](https://saythanks.io/to/BenjaminOddou)
6+
[![Python 3.7+](https://img.shields.io/badge/python-3.7+-7f0000.svg)](https://www.python.org/downloads/macos/)
7+
8+
Welcome to the Alfred Emoji Wine repository: **An Alfred Workflow**
9+
10+
## ✅ Prerequisites
11+
12+
* MacOS.
13+
* Alfred 5. Note that the [Alfred Powerpack](https://www.alfredapp.com/powerpack/) is required to use workflows.
14+
* Requires **python 3.7** or above.
15+
16+
## 🏎️ Data sources
17+
18+
This workflow combines multiple sources (see below) to build a local JSON API (`~/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/com.benjamino.emoji_wine`) along with an icons folder with base64 png images (≊1-4Ko per image).
19+
20+
List of sources :
21+
* [Full list of latest emojis](https://unicode.org/Public/emoji/latest/emoji-test.txt) - Used to grab the full list of emojis
22+
* [Classic emojis images](https://unicode.org/emoji/charts/full-emoji-list.html) - Used to grab list of classic emojis images
23+
* [Skin Tone emojis images](https://unicode.org/emoji/charts/full-emoji-modifiers.html) - Used to grab list of skin toned emojis images
24+
* [CLDR Data files annotations](https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotations) - Used to translate of emojis titles and keywords
25+
* [CLDR Data files annotations derived](https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotationsDerived) - Used to translate of emojis titles and keywords
26+
27+
## ⬇️ Installation
28+
29+
1. [Download the workflow](https://github.com/BenjaminOddou/alfred-emoji-wine/releases/latest)
30+
2. Double click the `.alfredworkflow` file to install
31+
32+
## 🧰 Setup the workflow
33+
34+
Install Python 3.7 or above. Check your version with :
35+
36+
```shell
37+
python --version
38+
```
39+
40+
## 🧙‍♂️ Invoke the workflow
41+
42+
There is 2 flows in this workflow :
43+
44+
1. The first one allows you to display emojis. It can be triggered by writing `wine` keyword.
45+
2. The second allows you to build the local api according the selected language. You can invoke this flow with the `harvest` keyword.
46+
47+
You can edit these triggers (flagged with a `🕹️` symbol) in the user configuration panel.
48+
49+
## 🤖 Usage of the workflow
50+
51+
### Setup variables
52+
53+
1. `🌐 Language` : select the language you prefer. Here is the full list of supported languages :
54+
55+
| Language | ISO 639-1 | Emojipedia link |
56+
| --------------- | --------- | --------------- |
57+
| 🇬🇧 English | en | 🟢 |
58+
| 🇫🇷 Français | fr | 🟢 |
59+
| 🇪🇸 Español | es | 🟢 |
60+
| 🇵🇹 Português | pt | 🟢 |
61+
| 🇮🇹 Italiano | it | 🟢 |
62+
| 🇩🇪 Deutsch | de | 🟢 |
63+
| 🇳🇱 Nederlands | nl | 🟢 |
64+
| 🇳🇴 Norsk | no | 🟢 |
65+
| 🇸🇪 Svenska | se | 🟢 |
66+
| 🇩🇰 Dansk | dk | 🟢 |
67+
| 🇮🇩 Melayu | ms | 🟢 |
68+
| 🇨🇳 中文 | zh | 🟢 |
69+
| 🇯🇵 日本語 | ja | 🟢 |
70+
| 🇰🇷 한국어 | ko | 🟢 |
71+
| 🇮🇳 हिंदी | hi | 🔴 |
72+
| 🇮🇳 मराठी | mr | 🔴 |
73+
| 🇮🇳 తెలుగు | te | 🔴 |
74+
| 🇧🇩 বাংলা | bn | 🔴 |
75+
| 🇱🇰 தமிழ் | ta | 🔴 |
76+
77+
> All emojis aren't translated in all languages. Some languages doesn't have an emojipedia link issue.
78+
79+
If you wish to use another language, open a GitHub issue [here](https://github.com/BenjaminOddou/alfred-emoji-wine/issues/new).
80+
81+
1. `🎷 Notification sound` : personalize the sound of the workflow notification.
82+
83+
### Search an emoji
84+
85+
Trigger the workflow with `wine` keyword and search for an your emoji in the selected language.
86+
87+
![search](public/search.webp)
88+
89+
### Workflow actions
90+
91+
1. Press ⏎ on the selected emoji to copy it to the clipboard.
92+
2. Press ⌘⏎ on the selected emoji to paste it to the frontmost application.
93+
3. Press ⌥⏎ on the selected emoji to copy its shortcut name (`:wine_glass:` ⇒ 🍷).
94+
4. Press ⇧⏎ on the selected emoji to open its emojipedia page in the selected language.
95+
96+
### Refresh the API
97+
98+
Use the `harvest` keyword to display the local API info and to refresh it.
99+
100+
![harvest](public/harvest.webp)
101+
102+
103+
## ⚖️ License
104+
105+
[MIT License](LICENSE) © Benjamin Oddou

public/harvest.webp

10.2 KB
Loading

public/icon_dark_mode.webp

8.03 KB
Loading

public/icon_light_mode.webp

8.3 KB
Loading

public/search.webp

7.4 KB
Loading
1.79 KB
Binary file not shown.

src/api.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import os
2+
import re
3+
import sys
4+
sys.path.insert(0, './lib')
5+
import base64
6+
import json
7+
import time
8+
import datetime
9+
from bs4 import BeautifulSoup
10+
from io import BytesIO
11+
from urllib import request
12+
import xml.etree.ElementTree as ET
13+
from utils import api_file_path, cache_folder_path, icons_folder_path, display_notification, language
14+
15+
display_notification('⏳ Please wait !', 'Emojis data is beeing gathered, this can take some time...')
16+
time.sleep(0.2)
17+
18+
for folder in [cache_folder_path, icons_folder_path]:
19+
if not os.path.exists(folder):
20+
os.mkdir(folder)
21+
22+
try:
23+
img_urls = ['https://unicode.org/emoji/charts/full-emoji-list.html', 'https://unicode.org/emoji/charts/full-emoji-modifiers.html']
24+
for url in img_urls:
25+
img_response = request.urlopen(url).read().decode('utf-8')
26+
soup = BeautifulSoup(img_response, 'html.parser')
27+
rows = soup.find_all('tr')
28+
for row in rows[1:]:
29+
cols = row.find_all('td')
30+
if cols:
31+
img_tag = cols[3].find('img')
32+
if img_tag:
33+
img_src = img_tag.get('src').split(',')[1]
34+
img_data = BytesIO(base64.b64decode(img_src))
35+
file_name = f'{cols[-1].text.replace("⊛", "").replace(":", "").strip()}.png'
36+
file_path = os.path.join(icons_folder_path, file_name)
37+
with open(file_path, 'wb') as file:
38+
file.write(img_data.getvalue())
39+
40+
api_url = 'https://unicode.org/Public/emoji/latest/emoji-test.txt'
41+
api_response = request.urlopen(api_url).read().decode('utf-8')
42+
lines = [line.strip() for line in api_response.split('\n') if ('; fully-qualified' in line) or ('; component' in line)]
43+
44+
lang_url_1 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotationsDerived/{language}.xml'
45+
lang_url_2 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotations/{language}.xml'
46+
lang_response_1 = request.urlopen(lang_url_1).read().decode('utf-8')
47+
lang_response_2 = request.urlopen(lang_url_2).read().decode('utf-8')
48+
49+
root = ET.fromstring(lang_response_1)
50+
root.extend(ET.fromstring(lang_response_2))
51+
52+
items = []
53+
for line in lines:
54+
array = re.split(r'\bfully-qualified\b|\bcomponent\b', line)[1].strip().split(' ', 3)
55+
emoji, name = array[1], array[-1]
56+
trim_emoji = re.sub('\uFE0F', '', emoji)
57+
for elem in root:
58+
keywords_list = elem.find(f"./annotation[@cp='{trim_emoji}']")
59+
title = elem.find(f"./annotation[@cp='{trim_emoji}'][@type='tts']")
60+
keywords = None
61+
if keywords_list is not None and title is not None:
62+
title = title.text
63+
keywords = keywords_list.text.split(' | ')
64+
break
65+
items.append({
66+
'name': name,
67+
'emoji': emoji,
68+
'title': title,
69+
'keywords': keywords
70+
})
71+
72+
with open('json/lang.json') as file:
73+
langs = json.load(file)
74+
for item in langs:
75+
if item["value"] == language:
76+
lang = item["title"]
77+
break
78+
info = {'time': datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"), 'lang': {'title': lang, 'value': language}}
79+
with open(api_file_path, 'w', encoding='utf-8') as file:
80+
json.dump({'info': info, 'items': items}, file, ensure_ascii=False, indent=4)
81+
82+
display_notification('✅ Success !', 'Data updated. You can search emojis.')
83+
except:
84+
display_notification('🚨 Error !', 'Something went wrong, check your internet connexion or report a GitHub issue')

src/harvest.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import json
2+
from utils import api
3+
4+
data = api()
5+
items = []
6+
7+
if data:
8+
num_object = len(data['items'])
9+
items = [
10+
{
11+
'title': 'Refresh the API',
12+
'subtitle': 'Press ⏎ to grab emoji data from unicode.org',
13+
'arg': '_api',
14+
'icon': {
15+
'path': 'icons/sync.webp',
16+
},
17+
},
18+
{
19+
'title': 'API information',
20+
'subtitle': f'Last update : {data["info"]["time"]} ǀ {num_object} Emojis ǀ {data["info"]["lang"]["title"]}',
21+
'valid': False,
22+
'icon': {
23+
'path': 'icons/info.webp',
24+
},
25+
}
26+
]
27+
else:
28+
items.append({
29+
'title': 'No API detected',
30+
'subtitle': 'Press ⏎ to grab emoji data from unicode.org',
31+
'arg': '_api',
32+
'icon': {
33+
'path': 'icons/info.webp',
34+
},
35+
})
36+
37+
38+
print(json.dumps({'items': items}))

src/icon.png

43.7 KB
Loading

0 commit comments

Comments
 (0)