File indexing completed on 2024-09-15 04:28:36
0001 #!/bin/python 0002 0003 # SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org> 0004 # SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> 0005 # SPDX-License-Identifier: BSD-2-Clause 0006 0007 import requests 0008 import re 0009 0010 0011 def escape_sequence(unicode_str: str, codepoint_spliter: str) -> str: 0012 codepoints = unicode_str.split(codepoint_spliter) 0013 escape_sequence = "" 0014 for codepoint in codepoints: 0015 escape_sequence += "\\U" + codepoint.rjust(8, "0") 0016 return escape_sequence 0017 0018 0019 # GitLab uses the emoji shortnames from Gemojione 0020 # See also: https://docs.gitlab.com/ee/development/fe_guide/emojis.html 0021 gemojione = requests.get('https://raw.githubusercontent.com/bonusly/gemojione/master/config/index.json') 0022 emoji_unicode_shortname_map = {} 0023 gemojione_json = gemojione.json() 0024 for (shortcode, props) in gemojione_json.items(): 0025 escaped_sequence = escape_sequence(props['unicode'], "-") 0026 emoji_unicode_shortname_map[escaped_sequence] = shortcode 0027 0028 0029 response = requests.get('https://unicode.org/Public/emoji/14.0/emoji-test.txt') 0030 group = "" 0031 file = open("../src/emojis.h", "w") 0032 # REUSE-IgnoreStart 0033 file.write("// SPDX-FileCopyrightText: None\n") 0034 file.write("// SPDX-License-Identifier: LGPL-2.0-or-later\n") 0035 # REUSE-IgnoreEnd 0036 file.write("// This file is auto-generated. All changes will be lost. See tools/update-emojis.py\n") 0037 file.write("// clang-format off\n") 0038 0039 tones_file = open("../src/emojitones_data.h", "w") 0040 # REUSE-IgnoreStart 0041 tones_file.write("// SPDX-FileCopyrightText: None\n") 0042 tones_file.write("// SPDX-License-Identifier: LGPL-2.0-or-later\n") 0043 # REUSE-IgnoreEnd 0044 tones_file.write("// This file is auto-generated. All changes will be lost. See tools/update-emojis.py\n") 0045 tones_file.write("// clang-format off\n") 0046 0047 for line in response.text.split("\n"): 0048 if line.startswith("# group"): 0049 raw_group = line.split(": ")[1] 0050 if raw_group == "Activities": 0051 group = "Activities" 0052 elif raw_group == "Animals & Nature": 0053 group = "Nature" 0054 elif raw_group == "Component": 0055 group = "Component" 0056 elif raw_group == "Flags": 0057 group = "Flags" 0058 elif raw_group == "Food & Drink": 0059 group = "Food" 0060 elif raw_group == "Objects": 0061 group = "Objects" 0062 elif raw_group == "People & Body": 0063 group = "People" 0064 elif raw_group == "Smileys & Emotion": 0065 group = "Smileys" 0066 elif raw_group == "Symbols": 0067 group = "Symbols" 0068 elif raw_group == "Travel & Places": 0069 group = "Travel" 0070 else: 0071 print("Unknown group:" + group) 0072 group = "" 0073 elif line.startswith("#") or line == "": 0074 pass 0075 else: 0076 parts = line.split(";") 0077 first = parts[0].strip() 0078 escaped_sequence = escape_sequence(first, " ") 0079 0080 x = re.search(".*E[0-9]+.[0-9] ", parts[1]) 0081 description = parts[1].removeprefix(x.group()) 0082 shortcode = description 0083 if "flag:" in description: 0084 description = "Flag of " + description.split(": ")[1] 0085 0086 if "unqualified" in line or "minimally-qualified" in line: 0087 continue 0088 0089 is_skin_tone = "skin tone" in description 0090 0091 if escaped_sequence in emoji_unicode_shortname_map: 0092 shortcode = emoji_unicode_shortname_map[escaped_sequence] 0093 0094 emoji_args = 'QString::fromUtf8("{0}"), QStringLiteral("{1}"), QStringLiteral("{2}")'.format(escaped_sequence, shortcode, description) 0095 emoji_qvariant = 'QVariant::fromValue(Emoji{' + emoji_args + '})' 0096 0097 if is_skin_tone: 0098 tones_file.write("{QStringLiteral(\"" + description.split(":")[0] + "\"), " + emoji_qvariant + "},\n") 0099 continue 0100 file.write("_emojis[" + group + "].append(" + emoji_qvariant + ");\n") 0101 file.close() 0102 tones_file.close()