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_path: Path, out_path: Path, cache_dir: Path, config: Element14Config): in_db = load_db(in_path) out_parts = PartDb() client = Element14Client(config, cache_dir) for part in in_db.iterparts(): mpn = bom_file_utils.first_pn(part) query = mpn # TODO: support dpn out_id = query client.search(term="manuPartNum:" + query) out_part = types.Part(id=out_id, references=part.referencesProp) print("Saving {} work parts".format(out_parts.size())) save_db(out_path, out_parts, sort=True)