diff options
Diffstat (limited to 'src/ee/digikey')
-rw-r--r-- | src/ee/digikey/__init__.py | 9 | ||||
-rw-r--r-- | src/ee/digikey/search_parts.py | 11 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index 15eb5e6..b46ba85 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -126,8 +126,9 @@ class PriceBreak(object): class Document(object): - def __init__(self, kind: str, title: str, url: str): - self.kind = kind + def __init__(self, section: str, classes: List[str], title: str, url: str): + self.section = section + self.classes = classes self.title = title self.url = url @@ -464,7 +465,9 @@ class DigikeyParser(object): if href.startswith("//"): href = "https:" + href - docs.append(Document(kind, title, href)) + classes = [cls[3:].lower() for cls in a.get("class", "").split(" ") if cls.startswith("lnk")] + + docs.append(Document(kind, classes, title, href)) return docs diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py index a1236bb..c0da731 100644 --- a/src/ee/digikey/search_parts.py +++ b/src/ee/digikey/search_parts.py @@ -6,7 +6,7 @@ from ee.db import ObjDb from ee.digikey import Digikey, DigikeyParser, DigikeyClient, SearchResponseTypes, DigikeyProduct, DigikeyStore from ee.part import PartDb, load_db, save_db, Part from ee.tools import mk_parents -from ee.xml import types +from ee.xml import types, uris from ee.xml.uris import make_digikey_fact_key __all__ = ["search_parts"] @@ -157,8 +157,13 @@ def resolved(supplier, p: DigikeyProduct) -> Part: part.get_links().append(types.Link(url=p.url, relation="canonical", media_type="text/html")) for d in p.documents: - title = "{}: {}".format(d.kind, d.title) - part.get_links().append(types.Link(url=d.url, relation="http://purl.org/ee/link-relation#documentation", + title = "{}: {}".format(d.section, d.title) + relations = ["http://purl.org/ee/link-relation#documentation"] + + if "datasheet" in d.classes: + relations.append(uris.make_link_rel("datasheet")) + + part.get_links().append(types.Link(url=d.url, relation=" ".join(relations), media_type="text/html", title=title)) part.add_spn(p.part_number) |