瀏覽代碼

Add script for partial db update handling to reduce reingests

Kirk Trombley 2 年之前
父節點
當前提交
b53dea3e22
共有 1 個文件被更改,包括 29 次插入0 次删除
  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")