from GramAddict.core.telepathic_engine import TelepathicEngine

DUMP_PATH = "/Volumes/Alpha SSD/Coding/bot/debug/xml_dumps/post_load_timeout__2026-04-17_15-02-36.xml"
with open(DUMP_PATH, "r") as f:
    xml_content = f.read()

engine = TelepathicEngine.get_instance()
nodes = engine._extract_semantic_nodes(xml_content)
grid_nodes = []
for node in nodes:
    if node.get("resource_id") in [
        "com.instagram.android:id/grid_card_layout_container",
        "com.instagram.android:id/image_button",
    ]:
        grid_nodes.append(node)

grid_nodes.sort(key=lambda n: (round(n["y"] / 5) * 5, n["x"], n["naf"], -n["area"]))

for n in grid_nodes[:5]:
    print(f"Y={n['y']} (rnd={round(n['y']/5)*5}), NAF={n['naf']}, Area={n['area']}, ID={n['resource_id']}")
