diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-23 07:29:49 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-23 07:32:10 +0100 |
commit | 689508e07dba890fff8d1cd06e0029eca1c30994 (patch) | |
tree | 50898ade69fc853bf7310ee002767ba3990ae86a /src/ee/digikey/__init__.py | |
parent | 1fe278b37b4031a42f8e27ee4f3251b474efcb16 (diff) | |
download | ee-python-689508e07dba890fff8d1cd06e0029eca1c30994.tar.gz ee-python-689508e07dba890fff8d1cd06e0029eca1c30994.tar.bz2 ee-python-689508e07dba890fff8d1cd06e0029eca1c30994.tar.xz ee-python-689508e07dba890fff8d1cd06e0029eca1c30994.zip |
xsd:
o Adding <link> list on <part>. For media, datasheets etc.
digikey:
o Parsing out media.
PartDb:
o starting on a more generic object db with indexes.
order:
o Using the new object db for building data while resolving parts.
o Creating a report from the order.
Diffstat (limited to 'src/ee/digikey/__init__.py')
-rw-r--r-- | src/ee/digikey/__init__.py | 41 |
1 files changed, 41 insertions, 0 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']") |