45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""
|
|
To find best matches regardless of previous matches:
|
|
python pathToFile/BomGeneration.py "%I" "%O.csv"
|
|
To keep previous matches when possible:
|
|
python pathToFile/BomGeneration.py "%I" "%O.csv" %O.csv"
|
|
"""
|
|
|
|
import kicad_netlist_reader
|
|
import csv
|
|
import sys
|
|
import argparse
|
|
|
|
net = kicad_netlist_reader.netlist(sys.argv[1])
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("input", help="Input .xml netlist")
|
|
parser.add_argument("output", help="Output .csv file path")
|
|
parser.add_argument(
|
|
"previous",
|
|
default=None,
|
|
nargs="?",
|
|
help="Previous output. If provided, any matches from previous which are still valid will be retained",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
with open(args.input, "r") as infile:
|
|
old = ""
|
|
if args.previous:
|
|
with open(args.previous, "r") as oldfile:
|
|
old = oldfile.read()
|
|
|
|
# TODO: parse old
|
|
|
|
# jlcparts = requests.get(f"https://jlcpcb.com/componentSearch/uploadComponentInfo")
|
|
|
|
comments = [[]]
|
|
header = ["manufacturer", "manufacturer_part_number", "quantity", "designators"]
|
|
data = [["dummy", "dpn", 2, "U1 U4"]]
|
|
|
|
with open(args.output, "w", newline="") as outfile:
|
|
writer = csv.writer(outfile, delimiter=",", quotechar="'", quoting=csv.QUOTE_MINIMAL)
|
|
writer.writerows(comments)
|
|
writer.writerow(header)
|
|
writer.writerows(data)
|