aboutsummaryrefslogtreecommitdiff
path: root/src/ee/digikey
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/digikey')
-rw-r--r--src/ee/digikey/doit.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/ee/digikey/doit.py b/src/ee/digikey/doit.py
index 2b30d9b..6f7c2d5 100644
--- a/src/ee/digikey/doit.py
+++ b/src/ee/digikey/doit.py
@@ -1,5 +1,6 @@
import logging
from itertools import groupby
+from operator import itemgetter
from typing import List
import ee.digikey as dk
@@ -34,23 +35,42 @@ def resolve_schematic_components(output: DataSet, in_ds: DataSet):
digikey = dk.Digikey()
client = dk.DigikeyClient(digikey, on_download=logger.info)
- components = [(o.get_req("mpn"), o.get_req("ref")) for o in in_ds.items() if
- o.object_type.name == "component" and o.has("mpn", "ref")]
- components = sorted(components, key=lambda c: c[0])
+ components = []
- for mpn, components in groupby(components, key=lambda c: c[0]):
- references = [c[1] for c in components]
+ # TODO: support searching by value and digikey part number directly. Priority should be "digikey", "mpn" and
+ # "value", first field present should be used.
+
+ for o in in_ds.items():
+ if o.object_type.name != "component":
+ continue
+
+ ref, = o.values("ref", required=True)
+
+ if not ref:
+ raise Exception("Bad component: object key={}, missing required field 'ref'".format(o.key))
+
+ mpn, = o.values("mpn", strip=True)
- # TODO: support searching by value and digikey part number directly. Priority should be "digikey", "mpn" and
- # "value", first field present should be used.
+ # We ignore components without mpn.
+ if not mpn:
+ logger.debug("Skipping component without")
+ continue
+
+ components.append([mpn, ref])
+
+ components = sorted(components, key=itemgetter(0))
+
+ for mpn, components in groupby(components, key=itemgetter(0)):
+ references = [c[1] for c in components]
dk_components = find("mpn", mpn)
if len(dk_components):
- logger.info("Already resolved {} to {}".format(mpn, ", ".join(sorted(set([c.get("part-number") for c in dk_components])))))
+ logger.info("Already resolved {} to {}".format(mpn, ", ".join(
+ sorted(set([c.get("part-number") for c in dk_components])))))
continue
- logger.info("Looking up {}".format(mpn))
+ logger.info("Looking up MPN: {}, used by {}".format(mpn, ", ".join(sorted(references))))
response = client.search(mpn)
if response.response_type == dk.SearchResponseTypes.SINGLE:
@@ -101,10 +121,11 @@ doit_config.set_data_sets_for(task_digikey_resolve_schematic_components,
def download_part_facts(output: DataSet, in_ds: DataSet):
digikey = dk.Digikey()
- client = dk.DigikeyClient(digikey, on_download=logger.info)
+ client = dk.DigikeyClient(digikey, on_download=logger.debug)
- parts = [o for o in in_ds.items()
- if o.object_type.name == "component-to-part-mapping" and o.get("seller") == "digikey"]
+ parts = [o for o in in_ds.items() if
+ o.object_type.name == "component-to-part-mapping" and
+ o.get("seller") == "digikey"]
for pn in sorted({part.get("part-number") for part in parts}):
logger.info("Downloading facts for {}".format(pn))