#!/usr/bin/env python3 # # -*- coding: utf-8 -*- import json import re with open("../../extraction/raw-31-0/data.cdb.json") as f: raw = json.load(f) with open("../../clean/31-0/main.zh.mo.json") as f: trans = json.load(f) lines = raw["sheets"][1]["lines"] melee = [] for i in lines: if i["group"] == 4: melee.append(i) i["name"] = trans[i["name"]]["msgstr"][0] if "ambiantDesc" in i: i["ambiantDesc"] = trans[i["ambiantDesc"].strip()]["msgstr"][0] if "gameplayDesc" in i: i["gameplayDesc"] = trans[i["gameplayDesc"].strip()]["msgstr"][0] if i["props"]: def replace_props(m): result = i["props"][m.group(1)] if isinstance(result, list): result = result[0] if not isinstance(result, str): result = str(result) return result i["gameplayDesc"], _ = re.subn( r"::\+?(.*?)::", replace_props, i["gameplayDesc"] ) print(json.dumps(melee, ensure_ascii=False))