import re


def fix_footprint(filepath):
    with open(filepath, "r") as f:
        content = f.read()

    # Replace specific layer string for the thru_hole pads
    # It might be in the footprint file and the PCB file
    content = content.replace(
        '(layers "*.Cu" "F.Mask" "F.Paste")',
        '(layers "*.Cu" "*.Mask" "F.Paste" "B.Paste")',
    )
    content = content.replace('(layers "*.Cu" "F.Mask")', '(layers "*.Cu" "*.Mask")')

    with open(filepath, "w") as f:
        f.write(content)


fix_footprint(
    "boardloaf-he/boardloaf-CustomFoot.pretty/custom.pretty/C_0805_2012Metric_Pad1.18x1.45mm_HandSolder.kicad_mod"
)
fix_footprint("boardloaf-he/boardloafhe.kicad_pcb")

print("Fixed capacitor footprints.")
