aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ee/digikey/__init__.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py
index 003394e..934c0d2 100644
--- a/src/ee/digikey/__init__.py
+++ b/src/ee/digikey/__init__.py
@@ -91,6 +91,9 @@ class DigikeyProduct(object):
def __hash__(self):
return self.part_number.__hash__()
+ def attribute_by_id(self, _id):
+ return next((a for a in self.attributes if a.attribute_type.id == _id), None)
+
def to_ini(self, c: configparser.ConfigParser):
c["overview"] = {};
overview = c["overview"]
@@ -114,7 +117,7 @@ class DigikeyProduct(object):
attributes = []
for k, value in c.items("attributes"):
(type_id, label) = DigikeyProduct.from_ini_r.match(k).groups()
- a_type = digikey.get_attribute_type(type_id, label)
+ a_type = digikey.get_attribute_type(int(type_id), label)
attributes.append(DigikeyAttributeValue(value, a_type))
return DigikeyProduct(overview["part_number"], overview["mpn"], attributes)
@@ -299,13 +302,13 @@ class DigikeyRepository(object):
self._path = path
self._products = {}
- def mpn_to_path(self, mpn):
+ def _mpn_to_path(self, mpn):
mpn = mpn.replace("/", "_").replace(" ", "_")
return "{}/{}.ini".format(self._path, mpn)
def has_product(self, mpn=None, dpn=None):
if mpn is not None:
- filename = self.mpn_to_path(mpn)
+ filename = self._mpn_to_path(mpn)
return os.path.isfile(filename)
if dpn is not None:
for p in self.products:
@@ -315,7 +318,7 @@ class DigikeyRepository(object):
def save(self, product: DigikeyProduct):
c = self._make_configparser()
y = product.to_ini(c)
- filename = self.mpn_to_path(product.mpn)
+ filename = self._mpn_to_path(product.mpn)
mk_parents(filename)
with open(filename, "w") as f:
y.write(f)
@@ -341,4 +344,6 @@ class DigikeyRepository(object):
return self._products.values()
def find_by_mpn(self, mpn):
- return [p for p in self.products if p.mpn == mpn]
+ for p in self.products:
+ if p.mpn == mpn:
+ return p