| 1 | import base64, json, sys, urllib.request |
| 2 | EP = "http://hzk-surreal:8000/sql" |
| 3 | def sql(q, db="zeka"): |
| 4 | r = urllib.request.Request(EP, data=q.encode("utf-8")) |
| 5 | r.add_header("Accept", "application/json"); r.add_header("Content-Type", "text/plain; charset=utf-8") |
| 6 | r.add_header("surreal-ns", "hezarfen"); r.add_header("surreal-db", db) |
| 7 | r.add_header("Authorization", "Basic " + base64.b64encode(b"root:root").decode()) |
| 8 | with urllib.request.urlopen(r, timeout=600) as resp: |
| 9 | return json.loads(resp.read().decode("utf-8")) |
| 10 | man = json.load(open("/seed/MANIFEST.json", encoding="utf-8"))["tablo_satir_sayilari"] |
| 11 | q = "\n".join("SELECT count() FROM %s GROUP ALL;" % t for t in sorted(man)) |
| 12 | res = sql(q) |
| 13 | bad = [] |
| 14 | tot_db = tot_man = 0 |
| 15 | for t, r in zip(sorted(man), res): |
| 16 | got = 0 |
| 17 | if r.get("status") == "OK" and r.get("result"): |
| 18 | got = r["result"][0].get("count", 0) |
| 19 | exp = man[t] |
| 20 | tot_db += got; tot_man += exp |
| 21 | if got != exp: |
| 22 | bad.append((t, exp, got)) |
| 23 | print("tablo: %d | MANIFEST toplam: %d | DB toplam: %d" % (len(man), tot_man, tot_db)) |
| 24 | if bad: |
| 25 | print("UYUSMAYAN (%d):" % len(bad)) |
| 26 | for t, e, g in bad[:20]: |
| 27 | print(" %-24s beklenen %7d bulunan %7d" % (t, e, g)) |
| 28 | else: |
| 29 | print("TUM TABLOLAR BIREBIR UYUSUYOR") |