from pathlib import Path from ee.element14 import * from ee.part import PartDb, load_db, save_db from ee.xml import bom_file_utils, types __all__ = ["search_parts"] def search_parts(in_dir: Path, out_dir: Path, cache_dir: Path, config: Element14Config): in_db = load_db(in_dir) out_parts = PartDb() client = Element14Client(config, cache_dir) for part in in_db.iterparts(): mpn = bom_file_utils.find_pn(part) query = mpn # TODO: suppor dpn out_id = query client.search(term="manuPartNum:" + query) out_part = types.Part(id=out_id, distributor_info=types.DistributorInfo(), part_numbers=part.part_numbersProp) di = out_part.distributor_infoProp print("Saving {} work parts".format(out_parts.size())) save_db(out_dir, out_parts)