build_emoji: Use with for writing to files.

This is a nice code cleanup.
This commit is contained in:
Tim Abbott 2018-07-13 21:07:08 +05:30
parent 85243c525d
commit 7a86e83a6f
1 changed files with 11 additions and 16 deletions

View File

@ -189,7 +189,6 @@ def generate_map_files(cache_path, emoji_map, emoji_data, emoji_catalog, unified
# type: (str, Dict[str, str], List[Dict[str, Any]], Dict[str, List[str]], Dict[str, str]) -> None
# This function generates the various data files consumed by webapp, mobile apps, bugdown etc.
EMOJI_CODES_PATH = os.path.join(cache_path, 'emoji_codes.js')
emoji_codes_file = open(EMOJI_CODES_PATH, 'w')
# put thumbs_up before thumbs_down
names = emoji_names_for_picker(emoji_map)
@ -206,25 +205,21 @@ def generate_map_files(cache_path, emoji_map, emoji_data, emoji_catalog, unified
name_to_codepoint = get_extended_name_to_codepoint(name_to_codepoint, new_emoji_dicts)
codepoint_to_name = get_extended_codepoint_to_name(codepoint_to_name, new_emoji_dicts)
with open(EMOJI_CODES_PATH, 'w') as emoji_codes_file:
emoji_codes_file.write(EMOJI_CODES_FILE_TEMPLATE % {
'names': names,
'name_to_codepoint': name_to_codepoint,
'codepoint_to_name': codepoint_to_name,
'emoji_catalog': emoji_catalog,
})
emoji_codes_file.close()
NAME_TO_CODEPOINT_PATH = os.path.join(cache_path, 'name_to_codepoint.json')
name_to_codepoint_file = open(NAME_TO_CODEPOINT_PATH, 'w')
with open(NAME_TO_CODEPOINT_PATH, 'w') as name_to_codepoint_file:
name_to_codepoint_file.write(ujson.dumps(name_to_codepoint))
name_to_codepoint_file.close()
CODEPOINT_TO_NAME_PATH = os.path.join(cache_path, 'codepoint_to_name.json')
codepoint_to_name_file = open(CODEPOINT_TO_NAME_PATH, 'w')
with open(CODEPOINT_TO_NAME_PATH, 'w') as codepoint_to_name_file:
codepoint_to_name_file.write(ujson.dumps(codepoint_to_name))
codepoint_to_name_file.close()
def dump_emojis(cache_path):
# type: (str) -> None