#!/usr/bin/env python3 import json import re from pathlib import Path NEWSERV = Path.home() / ".local/share/github/psopeeps-newserv" OUT = Path("site/generated/drops/peeps") TABLES = { "v1": NEWSERV / "system/tables/rare-table-v1.json", "v2": NEWSERV / "system/tables/rare-table-v2.json", "v3": NEWSERV / "system/tables/rare-table-v3.json", "bb": NEWSERV / "system/tables/rare-table-v4.json", } def strip_json_comments(text): out = [] in_str = False esc = False i = 0 while i < len(text): c = text[i] n = text[i + 1] if i + 1 < len(text) else "" if in_str: out.append(c) if esc: esc = False elif c == "\\": esc = True elif c == '"': in_str = False i += 1 continue if c == '"': in_str = True out.append(c) i += 1 continue if c == "/" and n == "/": while i < len(text) and text[i] not in "\r\n": i += 1 continue out.append(c) i += 1 return "".join(out) def quote_hex_numbers(text): return re.sub(r'(?= 3 and drop[2] else "", }) return rows def main(): OUT.mkdir(parents=True, exist_ok=True) index = { "mode": "peeps", "label": "Peeps", "tables": [], } labels = {"v1": "V1", "v2": "V2", "v3": "V3", "bb": "BB"} for version, src in TABLES.items(): table = load_newserv_jsonish(src) rows = flatten_table(version, table) out_name = f"{version}.json" out_path = OUT / out_name out_path.write_text(json.dumps(rows, indent=2, sort_keys=True) + "\n") index["tables"].append({ "version": version, "label": labels[version], "path": out_name, "rows": len(rows), }) print(f"{version}: {len(rows)} rows -> {out_path}") index_path = OUT / "index.json" index_path.write_text(json.dumps(index, indent=2, sort_keys=True) + "\n") print(f"index -> {index_path}") if __name__ == "__main__": main()