with open("app/static/bim/index.html", "r", encoding="utf-8") as f:
    content = f.read()

dup_start = content.find('}nitial-scale=1.0">')

# The old block we were trying to replace ended with:
old_end_str = 'groupJoints.add(new THREE.Mesh(g, new THREE.MeshStandardMaterial({ color: 0xfacc15, side: THREE.DoubleSide })));\n      }'
dup_end = content.find(old_end_str, dup_start) + len(old_end_str)

if dup_start != -1 and dup_end != -1 + len(old_end_str):
    # We want to remove everything from dup_start up to dup_end
    content = content[:dup_start] + "}\n" + content[dup_end:]
    
    with open("app/static/bim/index.html", "w", encoding="utf-8") as f:
        f.write(content)
    print("Fixed duplication!")
else:
    print(f"Failed to find indices. dup_start: {dup_start}, dup_end: {dup_end}")
