22import sys
33import shutil
44import subprocess
5- from utils import api_file_path , data_folder_path , icons_folder_path , assets_folder_path , display_notification , language , padding , custom_logger , langs , workflow_version
5+ from utils import (
6+ api_file_path ,
7+ data_folder_path ,
8+ icons_folder_path ,
9+ assets_folder_path ,
10+ display_notification ,
11+ language ,
12+ padding ,
13+ custom_logger ,
14+ langs ,
15+ workflow_version ,
16+ )
17+
618
719def get_homebrew_prefix ():
820 try :
9- prefix = subprocess .check_output ([' brew' , ' --prefix' ])
21+ prefix = subprocess .check_output ([" brew" , " --prefix" ])
1022 return prefix
1123 except :
1224 return None
1325
26+
1427homebrew_prefix = get_homebrew_prefix ()
1528
1629if homebrew_prefix :
17- python_version = f' { sys .version_info .major } .{ sys .version_info .minor } '
18- pillow_dir = f' { homebrew_prefix } /Cellar/pillow'
30+ python_version = f" { sys .version_info .major } .{ sys .version_info .minor } "
31+ pillow_dir = f" { homebrew_prefix } /Cellar/pillow"
1932 try :
2033 latest_version = max (os .listdir (pillow_dir ))
21- pillow_path = os .path .join (pillow_dir , latest_version , f'lib/python{ python_version } /site-packages' )
34+ pillow_path = os .path .join (
35+ pillow_dir , latest_version , f"lib/python{ python_version } /site-packages"
36+ )
2237 sys .path .append (pillow_path )
2338 except :
2439 pass
@@ -28,14 +43,19 @@ def get_homebrew_prefix():
2843import datetime
2944from urllib import request
3045import xml .etree .ElementTree as ET
46+
3147try :
3248 from PIL import Image , ImageDraw , ImageFont
3349except Exception as e :
34- display_notification ('🚨 Error !' , 'Pillow is not detected, check the documentation to install it' )
35- custom_logger ('error' , e )
50+ display_notification (
51+ "🚨 Error !" , "Pillow is not detected, check the documentation to install it"
52+ )
53+ custom_logger ("error" , e )
3654 exit ()
3755
38- display_notification ('⏳ Please wait !' , 'Emojis data is beeing gathered, this can take some time...' )
56+ display_notification (
57+ "⏳ Please wait !" , "Emojis data is beeing gathered, this can take some time..."
58+ )
3959
4060if os .path .exists (icons_folder_path ):
4161 shutil .rmtree (icons_folder_path )
@@ -45,12 +65,15 @@ def get_homebrew_prefix():
4565if not os .path .exists (data_folder_path ):
4666 os .mkdir (data_folder_path )
4767
48- check_e_type = ['flag:' , 'keycap:' ]
68+ check_e_type = ["flag:" , "keycap:" ]
69+
4970
5071def is_blank_image (image ):
5172 """Efficiently checks if an image is blank (fully transparent or one solid color)."""
5273 pixels = image .getdata ()
53- first_pixel = next (iter (pixels )) # Get the first pixel without loading all into memory
74+ first_pixel = next (
75+ iter (pixels )
76+ ) # Get the first pixel without loading all into memory
5477
5578 all_same = True
5679 all_transparent = True
@@ -65,55 +88,72 @@ def is_blank_image(image):
6588
6689 return all_same or all_transparent # Returns True if either condition is met
6790
91+
6892def convert_emoji_to_png (emoji , name ):
69- image_size = (64 + padding , 64 + padding ) # set image size
70- image = Image .new (' RGBA' , image_size , (0 , 0 , 0 , 0 )) # Set transparent background
93+ image_size = (64 + padding , 64 + padding ) # set image size
94+ image = Image .new (" RGBA" , image_size , (0 , 0 , 0 , 0 )) # Set transparent background
7195 font_size = 64 # Adjusted font size
72- font_path = '/System/Library/Fonts/Apple Color Emoji.ttc'
73- font = ImageFont .truetype (font_path , font_size , encoding = 'unic' )
74- draw_position = (int ((image_size [0 ] - font_size ) / 2 ), int ((image_size [1 ] - font_size ) / 2 ))
96+ font_path = "/System/Library/Fonts/Apple Color Emoji.ttc"
97+ font = ImageFont .truetype (font_path , font_size , encoding = "unic" )
98+ draw_position = (
99+ int ((image_size [0 ] - font_size ) / 2 ),
100+ int ((image_size [1 ] - font_size ) / 2 ),
101+ )
75102 draw = ImageDraw .Draw (image )
76103 draw .text (draw_position , emoji , font = font , embedded_color = True )
77104 if is_blank_image (image ):
78105 raise ValueError (f"Generated image for '{ emoji } ' is blank or unsupported." )
79- image .save (f'{ icons_folder_path } /{ name .replace (':' , '' )} .png' , 'PNG' )
106+ image .save (f"{ icons_folder_path } /{ name .replace (':' , '' )} .png" , "PNG" )
107+
80108
81109def remove_skin_tones (emoji ):
82110 skin_tone_range = range (0x1F3FB , 0x1F3FF + 1 )
83- clean_emoji = '' .join ([char for char in emoji if ord (char ) not in skin_tone_range ])
111+ clean_emoji = "" .join ([char for char in emoji if ord (char ) not in skin_tone_range ])
84112 return clean_emoji
85113
114+
86115def get_skin_tones (emoji ):
87116 skin_tones = []
88117 if emoji in cleaned_emojis :
89- skin_tones .append (' none' )
118+ skin_tones .append (" none" )
90119 else :
91120 skin_tone_dict = {
92- 0x1F3FB : ' light skin tone' ,
93- 0x1F3FC : ' medium-light skin tone' ,
94- 0x1F3FD : ' medium skin tone' ,
95- 0x1F3FE : ' medium-dark skin tone' ,
96- 0x1F3FF : ' dark skin tone'
121+ 0x1F3FB : " light skin tone" ,
122+ 0x1F3FC : " medium-light skin tone" ,
123+ 0x1F3FD : " medium skin tone" ,
124+ 0x1F3FE : " medium-dark skin tone" ,
125+ 0x1F3FF : " dark skin tone" ,
97126 }
98127 for char in emoji :
99128 value_skin_tone = skin_tone_dict .get (ord (char ))
100129 if value_skin_tone :
101130 skin_tones .append (value_skin_tone )
102131 if not skin_tones :
103- skin_tones .append (' base' )
132+ skin_tones .append (" base" )
104133 return list (set (skin_tones ))
105134
106- skin_tones = ['light skin tone' , 'medium-light skin tone' , 'medium skin tone' , 'medium-dark skin tone' , 'dark skin tone' ]
135+
136+ skin_tones = [
137+ "light skin tone" ,
138+ "medium-light skin tone" ,
139+ "medium skin tone" ,
140+ "medium-dark skin tone" ,
141+ "dark skin tone" ,
142+ ]
107143
108144try :
109- api_url = 'https://unicode.org/Public/emoji/latest/emoji-test.txt'
110- api_response = request .urlopen (api_url ).read ().decode ('utf-8' )
111- lines = [line .strip () for line in api_response .split ('\n ' ) if ('; fully-qualified' in line ) or ('; component' in line )]
145+ api_url = "https://unicode.org/Public/emoji/latest/emoji-test.txt"
146+ api_response = request .urlopen (api_url ).read ().decode ("utf-8" )
147+ lines = [
148+ line .strip ()
149+ for line in api_response .split ("\n " )
150+ if ("; fully-qualified" in line ) or ("; component" in line )
151+ ]
112152
113153 lang_url_1 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotations/{ language .replace ("-" , "_" )} .xml'
114154 lang_url_2 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotationsDerived/{ language .replace ("-" , "_" )} .xml'
115- lang_response_1 = request .urlopen (lang_url_1 ).read ().decode (' utf-8' )
116- lang_response_2 = request .urlopen (lang_url_2 ).read ().decode (' utf-8' )
155+ lang_response_1 = request .urlopen (lang_url_1 ).read ().decode (" utf-8" )
156+ lang_response_2 = request .urlopen (lang_url_2 ).read ().decode (" utf-8" )
117157
118158 root = ET .fromstring (lang_response_1 )
119159 root .extend (ET .fromstring (lang_response_2 ))
@@ -123,66 +163,78 @@ def get_skin_tones(emoji):
123163 full_emojis = []
124164
125165 for line in lines :
126- array = re .split (r'\bfully-qualified\b|\bcomponent\b' , line )[1 ].strip ().split (' ' , 3 )
166+ array = (
167+ re .split (r"\bfully-qualified\b|\bcomponent\b" , line )[1 ]
168+ .strip ()
169+ .split (" " , 3 )
170+ )
127171 emoji , name = array [1 ], array [- 1 ]
128- full_emojis .append ({' emoji' : emoji , ' name' : name })
172+ full_emojis .append ({" emoji" : emoji , " name" : name })
129173 clean_emoji = remove_skin_tones (emoji )
130174 if emoji != clean_emoji :
131175 cleaned_emojis .append (clean_emoji )
132-
176+
133177 for obj in full_emojis :
134- emoji , name = obj [' emoji' ], obj [' name' ]
135- trim_emoji = re .sub (' \uFE0F ' , '' , emoji )
178+ emoji , name = obj [" emoji" ], obj [" name" ]
179+ trim_emoji = re .sub (" \ufe0f " , "" , emoji )
136180 for elem in root :
137181 tags_list = elem .find (f"./annotation[@cp='{ trim_emoji } ']" )
138182 title = elem .find (f"./annotation[@cp='{ trim_emoji } '][@type='tts']" )
139183 tags = None
140184 if tags_list is not None and title is not None :
141185 title = title .text
142186 if any (substring in name for substring in check_e_type ):
143- tags = title .replace (':' , '' ).split (' ' )
187+ tags = title .replace (":" , "" ).split (" " )
144188 for i in range (len (tags )):
145189 tags [i ] = tags [i ].strip ()
146190 else :
147- tags = tags_list .text .split (' | ' )
191+ tags = tags_list .text .split (" | " )
148192 tags .append (emoji )
149193 break
150194 try :
151195 convert_emoji_to_png (emoji , name )
152196 image = True
153197 except Exception as e :
154- custom_logger (' error' , f' { emoji } cannot be transform into an image, { e } ' )
198+ custom_logger (" error" , f" { emoji } cannot be transform into an image, { e } " )
155199 image = False
156- items .append ({
157- 'name' : name ,
158- 'emoji' : emoji ,
159- 'title' : title ,
160- 'tags' : tags ,
161- 'image' : image ,
162- 'skin_tones' : get_skin_tones (emoji )
163- })
200+ items .append (
201+ {
202+ "name" : name ,
203+ "emoji" : emoji ,
204+ "title" : title ,
205+ "tags" : tags ,
206+ "image" : image ,
207+ "skin_tones" : get_skin_tones (emoji ),
208+ }
209+ )
164210
165211 for item in langs :
166- if item [' value' ] == language :
167- lang = item [' title' ]
212+ if item [" value" ] == language :
213+ lang = item [" title" ]
168214 break
169- info = {'time' : datetime .datetime .now ().strftime ('%d-%m-%Y %H:%M:%S' ), 'lang' : {'title' : lang , 'value' : language }, 'workflow_version' : workflow_version }
170- with open (api_file_path , 'w' , encoding = 'utf-8' ) as file :
171- json .dump ({'info' : info , 'items' : items }, file , ensure_ascii = False , indent = 4 )
215+ info = {
216+ "time" : datetime .datetime .now ().strftime ("%d-%m-%Y %H:%M:%S" ),
217+ "lang" : {"title" : lang , "value" : language },
218+ "workflow_version" : workflow_version ,
219+ }
220+ with open (api_file_path , "w" , encoding = "utf-8" ) as file :
221+ json .dump ({"info" : info , "items" : items }, file , ensure_ascii = False , indent = 4 )
172222
173223 assets = [f for f in os .listdir (assets_folder_path )]
174224
175225 for i in assets :
176226 image_path = os .path .join (assets_folder_path , i )
177227 image = Image .open (image_path )
178228 width , height = image .size
179- new_image = Image .new (' RGBA' , (width + padding , height + padding ), (0 , 0 , 0 , 0 ))
229+ new_image = Image .new (" RGBA" , (width + padding , height + padding ), (0 , 0 , 0 , 0 ))
180230 new_image .paste (image , (int (padding / 2 ), int (padding / 2 )))
181231 output_path = os .path .join (icons_folder_path , i )
182232 new_image .save (output_path )
183233
184- display_notification (' ✅ Success !' , ' Data updated. You can search emojis' )
185- custom_logger (' info' , f' API refreshed with language : { language } ' )
234+ display_notification (" ✅ Success !" , " Data updated. You can search emojis" )
235+ custom_logger (" info" , f" API refreshed with language : { language } " )
186236except Exception as e :
187- display_notification ('🚨 Error !' , 'Something went wrong, check the logs and create a GitHub issue' )
188- custom_logger ('error' , e )
237+ display_notification (
238+ "🚨 Error !" , "Something went wrong, check the logs and create a GitHub issue"
239+ )
240+ custom_logger ("error" , e )
0 commit comments