diff --git a/scripting/plugins/BomGeneration/BomGeneration.py b/scripting/plugins/BomGeneration/BomGeneration.py new file mode 100644 index 0000000..92f3452 --- /dev/null +++ b/scripting/plugins/BomGeneration/BomGeneration.py @@ -0,0 +1,46 @@ +""" +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 +import numpy as np +import requests + +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) diff --git a/scripting/plugins/BomGeneration/jlcparts.py b/scripting/plugins/BomGeneration/jlcparts.py index b9d83e1..ae82a24 100644 --- a/scripting/plugins/BomGeneration/jlcparts.py +++ b/scripting/plugins/BomGeneration/jlcparts.py @@ -68,7 +68,8 @@ logger.info("Parsing JLCPCB stock...") stock = parts_csv[parts_csv["Stock"] > 0] # NOTES: -# - if something has tolerance specified as absolute, "Value" may be wrong but "Tolerance" will be NA so it will be dropped +# if something has tolerance specified as absolute, +# "Value" may be wrong but "Tolerance" will be NA so it will be dropped # resistors resistors = stock[stock["First Category"] == "Resistors"].copy()