import json
import os

ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
MACHINES_FILE = os.path.join(ROOT, "machines.json")

# Load machines
with open(MACHINES_FILE, "r") as f:
    machines = json.load(f)

# Fix generation format
for m in machines:
    gen = m.get("generation", "")
    if gen == "2th Gen":
        m["generation"] = "2nd Gen"
        print(f"Fixed {m['computer_name']}: 2th Gen -> 2nd Gen")
    elif gen == "3th Gen":
        m["generation"] = "3rd Gen"
        print(f"Fixed {m['computer_name']}: 3th Gen -> 3rd Gen")

# Save
with open(MACHINES_FILE, "w") as f:
    json.dump(machines, f, indent=4)

print("Generation format cleanup complete!")
