aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-10-02 16:32:42 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-10-02 16:32:42 +0200
commitb735e67fef864b675d86a33eb8409d379bd62307 (patch)
treecf85cdcaf72dfacfa098798940b01eb7f406717b /src/ee/tools
parent2ace57ab4fb78ce72798afd3da11c91bc3098e0d (diff)
downloadee-python-b735e67fef864b675d86a33eb8409d379bd62307.tar.gz
ee-python-b735e67fef864b675d86a33eb8409d379bd62307.tar.bz2
ee-python-b735e67fef864b675d86a33eb8409d379bd62307.tar.xz
ee-python-b735e67fef864b675d86a33eb8409d379bd62307.zip
o Sorting products before downloading to be consistent across runs.
o Storing the URL for each product.
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/digikey_download_facts.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/ee/tools/digikey_download_facts.py b/src/ee/tools/digikey_download_facts.py
index 9842c40..cc75f74 100644
--- a/src/ee/tools/digikey_download_facts.py
+++ b/src/ee/tools/digikey_download_facts.py
@@ -97,14 +97,12 @@ for q in queries:
if len(viable_products):
# Pick the first one, should be as good as any
- part_number = viable_products[0].part_number
+ part_number = sorted(viable_products, key=lambda p: p.part_number)[0].part_number
log.info("Got many hits for term '{}', will use {} for downloading attributes.".format(q.query, part_number))
todos.append(part_number)
else:
- for k, g in hits:
- log.info("Got many results with many parts: {}: {}".format(k, list(g)))
- on_product(list(g)[0])
+ log.warn("Got many results: {}".format(", ".join([p.part_number for p in response.products])))
elif response.response_type == SearchResponseTypes.TOO_MANY:
log.warn("Too many results ({}), select a category first".format(response.count))
elif response.response_type == SearchResponseTypes.NO_MATCHES:
@@ -114,7 +112,7 @@ for q in queries:
response = client.search(part_number)
if response.response_type == SearchResponseTypes.SINGLE:
- p = response.products[0]
+ p = sorted(response.products, key=lambda p: p.part_number)[0]
log.info("Downloaded {}".format(p.mpn))
on_product(p)
else: