aboutsummaryrefslogtreecommitdiff
path: root/src/ee/digikey/search_parts.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/digikey/search_parts.py')
-rw-r--r--src/ee/digikey/search_parts.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py
index fec5615..c7f981e 100644
--- a/src/ee/digikey/search_parts.py
+++ b/src/ee/digikey/search_parts.py
@@ -1,19 +1,18 @@
from pathlib import Path
from typing import List
-from ee.digikey import Digikey, DigikeyParser, DigikeyClient, SearchResponseTypes, DigikeyProduct
+from ee.digikey import Digikey, DigikeyParser, DigikeyClient, SearchResponseTypes, DigikeyProduct, DigikeyStore
from ee.part import PartDb, load_db, save_db, Part
-from ee.project import Project
from ee.xml import types
-from ee.xml.uris import DIGIKEY_URI, make_digikey_fact_key
+from ee.xml.uris import make_digikey_fact_key
__all__ = ["search_parts"]
-def resolved(p: DigikeyProduct) -> Part:
+def resolved(supplier, p: DigikeyProduct) -> Part:
# TODO: fix uri
xml = types.Part(uri="https://digikey.com/pn#{}".format(p.part_number),
- supplier=DIGIKEY_URI,
+ supplier=supplier,
description=p.description,
distributor_info=types.DistributorInfo(state="resolved"),
links=types.LinkList(),
@@ -50,15 +49,17 @@ def resolved(p: DigikeyProduct) -> Part:
return part
-def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
+def search_parts(in_path: Path, out_path: Path, cache_dir: Path, store_code):
in_db = load_db(in_path)
out_parts = PartDb()
+ store = DigikeyStore.from_store_code(store_code)
+
parser = DigikeyParser(Digikey())
- client = DigikeyClient(cache_dir)
+ client = DigikeyClient(store.products_url, cache_dir)
for xml in in_db.iterparts():
- if xml.supplierProp is not None and xml.supplierProp != DIGIKEY_URI:
+ if xml.supplierProp is not None and xml.supplierProp != store.url:
continue
part = Part(xml)
@@ -83,7 +84,7 @@ def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
out_id = query
out_part = types.Part(uri=out_id,
distributor_info=types.DistributorInfo(),
- supplier=DIGIKEY_URI,
+ supplier=store.url,
references=xml.referencesProp)
di = out_part.distributor_infoProp
@@ -91,7 +92,7 @@ def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
response = parser.parse_string(text)
if response.response_type == SearchResponseTypes.SINGLE:
- out_part = resolved(response.products[0])
+ out_part = resolved(store.url, response.products[0])
elif response.response_type == SearchResponseTypes.MANY:
# find those with an exact match. Digikey uses a prefix search so a query for "FOO" will return "FOO"
@@ -108,7 +109,7 @@ def search_parts(in_path: Path, out_path: Path, cache_dir: Path):
response = parser.parse_string(client.search(dpn))
if response.response_type == SearchResponseTypes.SINGLE:
- out_part = resolved(response.products[0])
+ out_part = resolved(store.url, response.products[0])
else:
di.stateProp = "many"