From 5fdd957c8da72a5c3e421dee74ed54a6fc17606f Mon Sep 17 00:00:00 2001 From: Michael W Date: Fri, 24 Mar 2023 23:25:43 +0100 Subject: [PATCH] emoji-updater: Apply found data to LatinIME * Instead of having to sort the data manually, try finding the parts to be replaced automatically * Print out whatever could not be applied in the same way as before Change-Id: I297897cc934556a925dd1569a4c0f7bd95aed670 --- emoji-updater/emoji-updater.py | 68 +++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/emoji-updater/emoji-updater.py b/emoji-updater/emoji-updater.py index 227956e..f737a2a 100755 --- a/emoji-updater/emoji-updater.py +++ b/emoji-updater/emoji-updater.py @@ -1,18 +1,74 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import os +import requests import sys -import requests +from pathlib import Path -if __name__ == '__main__': +if __name__ == "__main__": if len(sys.argv) < 2: - sys.exit(f'usage: {sys.argv[0]} [url|https://unicode.org/Public/emoji/15.0/emoji-test.txt]') + sys.exit( + f"usage: {sys.argv[0]} [url|https://unicode.org/Public/emoji/15.0/emoji-test.txt]" + ) url = sys.argv[1] req = requests.get(url=url) + group_name = "" + items = {} + for line in req.text.splitlines(): - if line.startswith('# subgroup: '): - print(f' ') + if line.startswith("# subgroup: "): + group_name = line.split(maxsplit=2)[-1] elif '; fully-qualified' in line and not 'skin tone' in line: - print(f' {line.split(";")[0].strip().replace(" ", ",")}') + item = line.split(";")[0].strip().replace(" ", ",") + items.setdefault(group_name, []).append(item) + + # We want to transfer the received data into the target file + absolute_path = os.path.dirname(__file__) + relative_path = "../../../packages/inputmethods/LatinIME/java/res/values-v19/emoji-categories.xml" + target_path = Path(os.path.join(absolute_path, relative_path)).resolve() + + with open(target_path, "r+") as f: + lines = f.read() + f.seek(0) + f.truncate() + + for key in [*items.keys()]: + header = f"" + start = lines.find(header) + + if start != -1: + while start != -1: + end1 = lines.find("", start) + end2 = lines.find("" + + for c in items[key]: + built += f"\n {c}" + + print(built)