aboutsummaryrefslogtreecommitdiff
path: root/src/ee/digikey
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/digikey')
-rw-r--r--src/ee/digikey/__init__.py41
-rw-r--r--src/ee/digikey/search_parts.py13
2 files changed, 53 insertions, 1 deletions
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py
index d0405f1..2fe7443 100644
--- a/src/ee/digikey/__init__.py
+++ b/src/ee/digikey/__init__.py
@@ -79,6 +79,13 @@ class PriceBreak(object):
self.per_quantity_price = per_quantity_price
+class Document(object):
+ def __init__(self, kind: str, title: str, url: str):
+ self.kind = kind
+ self.title = title
+ self.url = url
+
+
@total_ordering
class DigikeyProduct(object):
def __init__(self, part_number, mpn, url, attributes: List["DigikeyAttributeValue"] = None, categories=None):
@@ -90,6 +97,7 @@ class DigikeyProduct(object):
self.quantity_available = None
self.description = None
self.price_breaks: List[PriceBreak] = []
+ self.documents: List[Document] = []
assert self.part_number
assert self.mpn
@@ -303,6 +311,7 @@ class DigikeyParser(object):
if part_number and mpn:
p = DigikeyProduct(part_number, mpn, url, attributes, categories)
p.price_breaks = self._parse_price_breaks(tree)
+ p.documents = self._parse_documents(tree)
for n in tree.xpath("//*[@itemprop='description']"):
p.description = _to_string(n)
return p
@@ -348,6 +357,38 @@ class DigikeyParser(object):
return price_breaks if ok else []
@staticmethod
+ def _parse_documents(tree: html) -> List[Document]:
+ docs = []
+
+ for row in tree.xpath("//*[@class='product-details-documents-media product-details-section']//tr"):
+ # print("row={}".format(row))
+ kind: str = _first(row.xpath(".//th/text()"))
+
+ if not kind:
+ continue
+
+ kind = kind.strip()
+
+ for a in row.xpath(".//td//a[not(contains(@class, '-expander-toggle'))]"):
+ # print("a={}".format(a))
+ title = a.text
+ if not title:
+ continue
+ title = title.strip()
+
+ href = a.get("href")
+ if not href:
+ continue
+
+ href = href.strip()
+ if href.startswith("//"):
+ href = "https:" + href
+
+ docs.append(Document(kind, title, href))
+
+ return docs
+
+ @staticmethod
def _handle_product_table(tree: html, res: DigikeySearchResponse):
products = tree.xpath("//*[@itemtype='http://schema.org/Product']")
diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py
index 3d271d5..358266a 100644
--- a/src/ee/digikey/search_parts.py
+++ b/src/ee/digikey/search_parts.py
@@ -13,9 +13,19 @@ def resolved(p: DigikeyProduct) -> types.Part:
# TODO: fix uri
part = types.Part(uri="https://digikey.com/pn#{}".format(p.part_number),
distributor_info=types.DistributorInfo(),
+ links=types.LinkList(),
facts=types.FactList(),
references=types.ReferencesList())
part.distributor_infoProp.stateProp = "resolved"
+ links = part.linksProp.link
+
+ if p.url:
+ links.append(types.Link(url=p.url, relation="canonical", media_type="text/html"))
+
+ for d in p.documents:
+ title = "{}: {}".format(d.kind, d.title)
+ links.append(types.Link(url=d.url, relation="http://purl.org/ee/link-relation#documentation",
+ media_type="text/html", title=title))
supplier_part_numbers = part.referencesProp.supplier_part_numberProp
supplier_part_numbers.append(types.SupplierPartNumber(value=p.part_number, supplier=DIGIKEY_URI))
@@ -48,7 +58,8 @@ def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
client = DigikeyClient(cache_dir)
for part in in_db.iterparts():
- dpn = next((p.valueProp for p in bom_file_utils.supplier_part_numbers(part) if p.supplierProp == DIGIKEY_URI), None)
+ 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