forge
Explore
Log in

Don't you dare go Hollow

hezarfen_zeka

Clone
★ 0

0 watching0 forksPython1.9 MiBe01a4faAhmet Kaan Gümüş2 months ago25 commits

check_rows.py29 lines, 1.2 KiBHistoryRawDownload
1import base64, json, sys, urllib.request
2EP = "http://hzk-surreal:8000/sql"
3def 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"))
10man = json.load(open("/seed/MANIFEST.json", encoding="utf-8"))["tablo_satir_sayilari"]
11q = "\n".join("SELECT count() FROM %s GROUP ALL;" % t for t in sorted(man))
12res = sql(q)
13bad = []
14tot_db = tot_man = 0
15for 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))
23print("tablo: %d | MANIFEST toplam: %d | DB toplam: %d" % (len(man), tot_man, tot_db))
24if 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))
28else:
29 print("TUM TABLOLAR BIREBIR UYUSUYOR")