#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import requests import sys from pathlib import Path 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]" ) url = sys.argv[1] req = requests.get(url=url) group_name = "" items = {} for line in req.text.splitlines(): if line.startswith("# subgroup: "): group_name = line.split(maxsplit=2)[-1] elif '; fully-qualified' in line and not 'skin tone' in line: 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)