Use more commonly-used emoji shortname
This commit is contained in:
@@ -1,27 +1,46 @@
|
||||
#!/bin/python
|
||||
|
||||
# SPDX-FileCopyrightText: 2022 Tobias Fella <fella@posteo.de>
|
||||
# SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
import requests
|
||||
import re
|
||||
|
||||
|
||||
def escape_sequence(unicode_str: str, codepoint_spliter: str) -> str:
|
||||
codepoints = unicode_str.split(codepoint_spliter)
|
||||
escape_sequence = ""
|
||||
for codepoint in codepoints:
|
||||
escape_sequence += "\\U" + codepoint.rjust(8, "0")
|
||||
return escape_sequence
|
||||
|
||||
|
||||
# GitLab uses the emoji shortnames from Gemojione
|
||||
# See also: https://docs.gitlab.com/ee/development/fe_guide/emojis.html
|
||||
gemojione = requests.get('https://raw.githubusercontent.com/bonusly/gemojione/master/config/index.json')
|
||||
emoji_unicode_shortname_map = {}
|
||||
gemojione_json = gemojione.json()
|
||||
for (shortcode, props) in gemojione_json.items():
|
||||
escaped_sequence = escape_sequence(props['unicode'], "-")
|
||||
emoji_unicode_shortname_map[escaped_sequence] = shortcode
|
||||
|
||||
|
||||
response = requests.get('https://unicode.org/Public/emoji/14.0/emoji-test.txt')
|
||||
group = ""
|
||||
file = open("../src/emojis.h", "w")
|
||||
# AAAAARGH reusetool
|
||||
file.write("// SPDX")
|
||||
file.write("-FileCopyrightText: None\n")
|
||||
file.write("// SPDX")
|
||||
file.write("-License-Identifier: LGPL-2.0-or-later\n")
|
||||
# REUSE-IgnoreStart
|
||||
file.write("// SPDX-FileCopyrightText: None\n")
|
||||
file.write("// SPDX-License-Identifier: LGPL-2.0-or-later\n")
|
||||
# REUSE-IgnoreEnd
|
||||
file.write("// This file is auto-generated. All changes will be lost. See tools/update-emojis.py\n")
|
||||
file.write("// clang-format off\n")
|
||||
|
||||
tones_file = open("../src/emojitones.h", "w")
|
||||
tones_file.write("// SPDX")
|
||||
tones_file.write("-FileCopyrightText: None\n")
|
||||
tones_file.write("// SPDX")
|
||||
tones_file.write("-License-Identifier: LGPL-2.0-or-later\n")
|
||||
# REUSE-IgnoreStart
|
||||
tones_file.write("// SPDX-FileCopyrightText: None\n")
|
||||
tones_file.write("// SPDX-License-Identifier: LGPL-2.0-or-later\n")
|
||||
# REUSE-IgnoreEnd
|
||||
tones_file.write("// This file is auto-generated. All changes will be lost. See tools/update-emojis.py\n")
|
||||
tones_file.write("// clang-format off\n")
|
||||
|
||||
@@ -56,22 +75,24 @@ for line in response.text.split("\n"):
|
||||
else:
|
||||
parts = line.split(";")
|
||||
first = parts[0].strip()
|
||||
codepoints = first.split(" ")
|
||||
escaped_sequence = escape_sequence(first, " ")
|
||||
|
||||
x = re.search(".*E[0-9]+.[0-9] ", parts[1])
|
||||
description = parts[1].removeprefix(x.group())
|
||||
if "flag:" in description:
|
||||
description = "Flag of " + description.split(": ")[1]
|
||||
|
||||
escape_sequence = ""
|
||||
for codepoint in codepoints:
|
||||
escape_sequence += "\\U" + codepoint.rjust(8, "0")
|
||||
|
||||
if "unqualified" in line or "minimally-qualified" in line:
|
||||
continue
|
||||
if "skin tone" in description:
|
||||
tones_file.write("{\"" + description.split(":")[0] + "\", QVariant::fromValue(Emoji{QString::fromUtf8(\"" + escape_sequence + "\"), QStringLiteral(\"" + description + "\")})},\n")
|
||||
|
||||
is_skin_tone = "skin tone" in description
|
||||
|
||||
if not is_skin_tone and escaped_sequence in emoji_unicode_shortname_map:
|
||||
description = emoji_unicode_shortname_map[escaped_sequence]
|
||||
|
||||
if is_skin_tone:
|
||||
tones_file.write("{\"" + description.split(":")[0] + "\", QVariant::fromValue(Emoji{QString::fromUtf8(\"" + escaped_sequence + "\"), QStringLiteral(\"" + description + "\")})},\n")
|
||||
continue
|
||||
file.write("_emojis[" + group + "].append(QVariant::fromValue(Emoji{QString::fromUtf8(\"" + escape_sequence + "\"), QStringLiteral(\"" + description + "\")}));\n")
|
||||
file.write("_emojis[" + group + "].append(QVariant::fromValue(Emoji{QString::fromUtf8(\"" + escaped_sequence + "\"), QStringLiteral(\"" + description + "\")}));\n")
|
||||
file.close()
|
||||
tones_file.close()
|
||||
|
||||
Reference in New Issue
Block a user