3
3
# Convert emoji file downloaded using tools/fetch-unicode-emoji-data
4
4
# into what is required by ZT.
5
5
6
- import os
7
6
from collections import OrderedDict
7
+ from pathlib import Path , PurePath
8
8
9
- from zulipterminal .unicode_emoji_dict import EMOJI_NAME_MAPS
10
9
10
+ try :
11
+ from zulipterminal .unicode_emoji_dict import EMOJI_NAME_MAPS
12
+ except ModuleNotFoundError :
13
+ print (
14
+ "ERROR: Could not find downloaded unicode emoji\n "
15
+ "Try fetching the unicode first using tools/fetch-unicode-emojis-data"
16
+ )
17
+ exit (1 )
11
18
12
- INPUT_FILE = "zulipterminal/unicode_emoji_dict.py"
13
- OUTPUT_FILE = "zulipterminal/unicode_emojis.py"
19
+ WORKING_FOLDER = Path (__file__ ).resolve ().parent .parent / "zulipterminal"
20
+ INPUT_FILE = WORKING_FOLDER / "unicode_emoji_dict.py"
21
+ OUTPUT_FILE = WORKING_FOLDER / "unicode_emojis.py"
22
+
23
+ SCRIPT_NAME = PurePath (__file__ ).name
14
24
15
25
emoji_dict = EMOJI_NAME_MAPS
16
26
@@ -22,19 +32,22 @@ for emoji_code, emoji_names in emoji_dict.items():
22
32
23
33
ordered_emojis = OrderedDict (sorted (emoji_map .items ()))
24
34
25
- with open (OUTPUT_FILE , "w" ) as f :
26
- f .write ('from collections import OrderedDict\n \n \n ' )
27
- f .write ('# Generated automatically by '
28
- 'tools/convert-unicode-emoji-data\n ' )
29
- f .write ('# Do not modify.\n \n ' )
30
- f .write ('EMOJI_DATA = OrderedDict([\n ' )
35
+ with OUTPUT_FILE .open ("w" ) as f :
36
+ f .write (
37
+ "from collections import OrderedDict\n \n \n "
38
+ f"# Generated automatically by tools/{ SCRIPT_NAME } \n "
39
+ "# Do not modify.\n \n "
40
+ "EMOJI_DATA = OrderedDict([\n "
41
+ )
31
42
for emoji_code , emoji_name in ordered_emojis .items ():
32
43
# {'smile': {'code': '263a'}}
33
- f .write (" ('%s', {'code': '%s'}),\n " % (emoji_code ,
34
- emoji_name ))
35
- f .write ('])\n ' )
36
-
37
- print ("Emoji list saved in {}" .format (OUTPUT_FILE ))
38
- if os .path .exists (INPUT_FILE ):
39
- os .remove (INPUT_FILE )
40
- print ("{} deleted." .format (INPUT_FILE ))
44
+ f .write (f" ('{ emoji_code } ', {{'code': '{ emoji_name } '}}),\n " )
45
+ f .write ("])\n " )
46
+
47
+ print (f"Emoji list saved in { OUTPUT_FILE } " )
48
+
49
+ try :
50
+ INPUT_FILE .unlink ()
51
+ print (f"{ INPUT_FILE } deleted." )
52
+ except Exception as exc :
53
+ print ("Warning: Could not delete file:\n {exc}" )
0 commit comments