- Jul
- 532
- 10
I wanted to have environment variables like %EMOJI_BROCCOLI% to use for emojis. For reasons.
I spent way too long programmatically generating these in python.
In the end, I created a file (emoji.env) that can be read with "set /r emoji.env" in about 0.7 seconds to grant access to about 1300 working emojis via environment variable.
This lets you echo emojis via environment variables, like so:
The file looks like this:
And gives you environment variables like this:
It's not very tested, but they mostly work, some empty boxes but it looks like >90% work:
I hit quite a few brick walls trying to generate a better list. This one is flawed. I would love if someone could make my code even better:
'''
I spent way too long programmatically generating these in python.
In the end, I created a file (emoji.env) that can be read with "set /r emoji.env" in about 0.7 seconds to grant access to about 1300 working emojis via environment variable.
This lets you echo emojis via environment variables, like so:
The file looks like this:
Code:
EMOJI_BICYCLE=%@CHAR[55357]%@CHAR[57010]
EMOJI_BIKINI=%@CHAR[55357]%@CHAR[56409]
EMOJI_BILLED_CAP=%@CHAR[55358]%@CHAR[56802]
EMOJI_BIOHAZARD=%@CHAR[9763]%@CHAR[65039]
EMOJI_BIRD=%@CHAR[55357]%@CHAR[56358]
EMOJI_BIRTHDAY_CAKE=%@CHAR[55356]%@CHAR[57218]
EMOJI_BISON=%@CHAR[55358]%@CHAR[56748]
EMOJI_BITING_LIP=%@CHAR[55358]%@CHAR[57062]
EMOJI_BLACK_CAT=%@CHAR[55357]%@CHAR[56328]
EMOJI_BLACK_CIRCLE=%@CHAR[9899]%@CHAR[0]
EMOJI_BLACK_HEART=%@CHAR[55357]%@CHAR[56740]
EMOJI_BLACK_LARGE_SQUARE=%@CHAR[11035]%@CHAR[0]
And gives you environment variables like this:
It's not very tested, but they mostly work, some empty boxes but it looks like >90% work:
I hit quite a few brick walls trying to generate a better list. This one is flawed. I would love if someone could make my code even better:
Code:
import emoji
def create_script_to_define_emoji_characters(): #2860, 1431 unique
print("EMOJI_ENVIRONMENT_VARIABLES_CREATED_BY=fix_unicode_files.py script")
import ctypes
from emoji.unicode_codes import EMOJI_DATA
processed_emojis = set() # Set to track processed emojis
rights = set() # Set to track right half of = in output file so we don't make duplicates
output_strings = set() # Set to handle duplicate output strings
for emoji, emoji_data in EMOJI_DATA.items():
# Fetch the base emoji without any skin tone variation
base_emoji = emoji.split('\u200d')[0]
emoji_name_meat = emoji_data['en'].upper().replace(' ', '_').replace(':', '').replace('-', '_').replace("'", '').replace('SKIN_TONE', 'SKIN').replace('&', '_AND_')
# Construct the fully qualified and unqualified names
fully_qualified_name = f"EMOJI_{emoji_name_meat}"
unqualified_name = f"EMOJI_{emoji_name_meat}_UNQUALIFIED"
# Determine the name to be used based on the status of the emoji
if emoji_data['status'] == 3: #rem emoji.fully_qualified:component = 1 fully_qualified = 2 minimally_qualified = 3 unqualified = 4
emoji_name = unqualified_name
else:
emoji_name = fully_qualified_name
# Check if the current version of this emoji has already been processed
if emoji_name in processed_emojis:
continue
processed_emojis.add(emoji_name)
# Convert the emoji into a ctypes wide string
# Then cast it to a pointer to short (16-bit) integers, and fetch the values
emoji_code_units = ctypes.cast(ctypes.c_wchar_p(emoji), ctypes.POINTER(ctypes.c_uint16))
# Create the output string
right = ""
for i in range(2): # two UTF-16 code units
right += f"%@CHAR[{emoji_code_units}]"
if right in rights:
continue
rights.add(right)
output_string = f"{emoji_name}={right}"
output_strings.add(output_string) # Add to a set to handle duplicates
# Print the output strings
printed = set()
for output_string in output_strings:
if output_string in printed: continue
printed.add(output_string)
print(output_string)
'''
Last edited: