1234567891011121314151617181920212223242526272829 |
- from sys import argv
- import json
- def read(f: str) -> dict[str, dict]:
- with open(f) as infile:
- next(infile)
- return {
- (d := json.loads(s))["name"]: d
- for line in infile
- if (s := line.strip().strip(",")) != "]"
- }
- _, new, old = argv
- db = read(old)
- db.update(read(new))
- output = [
- f" {json.dumps(s)},\n"
- for s in sorted(
- db.values(),
- key=lambda x: (x["num"], x["name"])
- )
- ]
- with open(old, "w") as outfile:
- outfile.write("const database = [\n")
- outfile.writelines(output)
- outfile.write("]\n")
|