from kicad_sym import *

def make_pins(lines, half_width):
    for ix, line in enumerate(lines):
        number, name, type = line[:3]
        x = u(-half_width) if number[0] == 'A' else u(half_width)
        y = u((-ix + 0) * 2) if number[0] == 'A' else u((-ix + 67) * 2)
        r = 0 if number[0] == 'A' else 180
        yield pin(x, y, r, number, name, type)

def make_lib(lines):
    half_width = 12
    pins = list(make_pins(lines, half_width))
    return lib([
        symbol("CN1", "CN1",
               pins,
               u(-half_width), u(2),
               u(half_width),  u(-len(pins)))
    ])

lines = read_txt("cn1.txt")
print(make_lib(lines))
