aboutsummaryrefslogtreecommitdiff
path: root/src/ee/digikey
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-03-15 14:55:15 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-03-15 14:55:15 +0100
commit237a6faa8a23826e68bbc00bc107b2d6f97235d0 (patch)
treefe1a6a6b1a4ed991a6eacd9ec6960325db3f9e4f /src/ee/digikey
parent3523190bb7ca1c38caea3a1aae51062d22e56b09 (diff)
downloadee-python-237a6faa8a23826e68bbc00bc107b2d6f97235d0.tar.gz
ee-python-237a6faa8a23826e68bbc00bc107b2d6f97235d0.tar.bz2
ee-python-237a6faa8a23826e68bbc00bc107b2d6f97235d0.tar.xz
ee-python-237a6faa8a23826e68bbc00bc107b2d6f97235d0.zip
Refactoring:
o Renaming part.id to part.uri. Changing to URIs and use that as an identifier if the part is known. Schematic part does not have an URI. o Merging <schema-reference> and <part-numbers> into <references> o Creating <part-uri> as a possible <reference>. Used by order to point to other parts.
Diffstat (limited to 'src/ee/digikey')
-rw-r--r--src/ee/digikey/normalize_facts.py2
-rw-r--r--src/ee/digikey/search_parts.py29
2 files changed, 17 insertions, 14 deletions
diff --git a/src/ee/digikey/normalize_facts.py b/src/ee/digikey/normalize_facts.py
index 91ad4db..d7546c3 100644
--- a/src/ee/digikey/normalize_facts.py
+++ b/src/ee/digikey/normalize_facts.py
@@ -153,4 +153,4 @@ def normalize_facts(in_path: Path, out_path: Path):
out_parts.add_entry(part, True)
print("Saving {} work parts".format(out_parts.size()))
- save_db(out_path, out_parts)
+ save_db(out_path, out_parts, sort=True)
diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py
index 4f637c7..3d271d5 100644
--- a/src/ee/digikey/search_parts.py
+++ b/src/ee/digikey/search_parts.py
@@ -10,15 +10,17 @@ __all__ = ["search_parts"]
def resolved(p: DigikeyProduct) -> types.Part:
- part = types.Part(id=p.part_number,
- distributor_info=types.DistributorInfo(),
- facts=types.FactList(),
- part_numbers=types.PartNumberList())
+ # TODO: fix uri
+ part = types.Part(uri="https://digikey.com/pn#{}".format(p.part_number),
+ distributor_info=types.DistributorInfo(),
+ facts=types.FactList(),
+ references=types.ReferencesList())
part.distributor_infoProp.stateProp = "resolved"
- part_numbers = part.part_numbersProp.part_numberProp
+ supplier_part_numbers = part.referencesProp.supplier_part_numberProp
+ supplier_part_numbers.append(types.SupplierPartNumber(value=p.part_number, supplier=DIGIKEY_URI))
- part_numbers.append(types.PartNumber(value=p.part_number, distributor=DIGIKEY_URI))
+ part_numbers = part.referencesProp.part_numberProp
if p.mpn:
part_numbers.append(types.PartNumber(value=p.mpn))
facts: List[types.Fact] = part.factsProp.factProp
@@ -46,8 +48,8 @@ def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
client = DigikeyClient(cache_dir)
for part in in_db.iterparts():
- dpn = bom_file_utils.find_dpn(part, DIGIKEY_URI)
- mpn = bom_file_utils.find_pn(part)
+ dpn = next((p.valueProp for p in bom_file_utils.supplier_part_numbers(part) if p.supplierProp == DIGIKEY_URI), None)
+ mpn = next((p.valueProp for p in bom_file_utils.part_numbers(part)), None)
is_mpn = query = None
@@ -59,13 +61,14 @@ def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
is_mpn = True
if query is None:
- print("could not find pn or dpn: part.id={}".format(part.idProp))
+ # TODO: use schematic reference
+ print("could not find pn or dpn: part.uri={}".format(part.uriProp))
continue
out_id = query
- out_part = types.Part(id=out_id,
- distributor_info=types.DistributorInfo(),
- part_numbers=part.part_numbersProp)
+ out_part = types.Part(uri=out_id,
+ distributor_info=types.DistributorInfo(),
+ references=part.referencesProp)
di = out_part.distributor_infoProp
text = client.search(query)
@@ -101,4 +104,4 @@ def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
out_parts.add_entry(out_part, True)
print("Saving {} work parts".format(out_parts.size()))
- save_db(out_path, out_parts)
+ save_db(out_path, out_parts, sort=True)