Forráskód Böngészése

Add script for partial db update handling to reduce reingests

Kirk Trombley 2 éve
szülő
commit
b53dea3e22
1 módosított fájl, 29 hozzáadás és 0 törlés
  1. 29 0
      tools/merge-db.py

+ 29 - 0
tools/merge-db.py

@@ -0,0 +1,29 @@
+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")