72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Проверка сгенерированного index.html: JSON в feed-data и логика ленты."""
|
|
import json
|
|
import re
|
|
import sys
|
|
|
|
def main():
|
|
path = sys.argv[1] if len(sys.argv) > 1 else "/opt/docker/log-dashboard/html/index.html"
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
html = f.read()
|
|
|
|
m = re.search(r'<script type="application/json" id="feed-data">(.*?)</script>', html, re.DOTALL)
|
|
if not m:
|
|
print("FAIL: feed-data block not found")
|
|
return 1
|
|
|
|
raw = m.group(1).strip()
|
|
try:
|
|
data = json.loads(raw)
|
|
except Exception as e:
|
|
print("FAIL: JSON parse error:", e)
|
|
return 1
|
|
|
|
for key in ("feed", "geo", "domains"):
|
|
if key not in data:
|
|
print("FAIL: missing key", key)
|
|
return 1
|
|
|
|
feed, geo, domains = data["feed"], data["geo"], data["domains"]
|
|
if not isinstance(feed, list) or not isinstance(geo, dict) or not isinstance(domains, list):
|
|
print("FAIL: wrong types")
|
|
return 1
|
|
|
|
if len(feed) == 0:
|
|
print("WARN: feed is empty")
|
|
else:
|
|
e = feed[0]
|
|
for k in ("t", "d", "m", "p", "s", "c"):
|
|
if k not in e:
|
|
print("FAIL: feed entry missing", k)
|
|
return 1
|
|
|
|
# Симуляция getFiltered() + render() для страницы 1
|
|
domain = domains[0] if domains else ""
|
|
filtered = [x for x in feed if x["d"] == domain] if domain else feed
|
|
page_size = 100
|
|
current_page = 1
|
|
total_pages = max(1, (len(filtered) + page_size - 1) // page_size)
|
|
start = (current_page - 1) * page_size
|
|
page = filtered[start : start + page_size]
|
|
|
|
rows = []
|
|
for e in page:
|
|
geo_val = geo.get(e.get("c"), "—")
|
|
rows.append((e.get("t"), e.get("d"), e.get("m"), e.get("p"), e.get("s"), e.get("c"), geo_val))
|
|
|
|
if not page and filtered:
|
|
print("FAIL: page is empty but filtered has items")
|
|
return 1
|
|
if len(rows) != len(page):
|
|
print("FAIL: row count mismatch")
|
|
return 1
|
|
|
|
print("OK: feed entries:", len(feed))
|
|
print("OK: geo entries:", len(geo))
|
|
print("OK: domains:", len(domains))
|
|
print("OK: page 1 rows:", len(rows), "| sample:", rows[0][:3] if rows else "n/a")
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|