#!/usr/bin/env python3 """letters_to_ids.py '' — replace „row A", „row A, B" with the filed R-numbers in the README and in table.py (the drafts used letters because the IDs are taken only after the last pull).""" import json, os, re, sys EV = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ids = json.loads(sys.argv[1]) rx = re.compile(r"\brows? ([A-I](?:, [A-I])*)\b") for p in (os.path.join(EV, "README.md"), os.path.join(EV, "tools", "table.py")): s = open(p).read() s2 = rx.sub(lambda m: ", ".join(ids[x] for x in m.group(1).split(", ")), s) open(p, "w").write(s2) print(p, "replaced", len(rx.findall(s)), "left", len(rx.findall(s2)))