diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-08-12 12:54:49 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-08-12 12:54:49 +0200 |
commit | 46100d63fa462aad2732d01d9621fe799700c453 (patch) | |
tree | c329caeee5ad403deaca53e05a2c75ae09446674 | |
parent | 5c38560d8f1bfe2bb9ee60e237466f8620e0d806 (diff) | |
download | ee-python-46100d63fa462aad2732d01d9621fe799700c453.tar.gz ee-python-46100d63fa462aad2732d01d9621fe799700c453.tar.bz2 ee-python-46100d63fa462aad2732d01d9621fe799700c453.tar.xz ee-python-46100d63fa462aad2732d01d9621fe799700c453.zip |
digikey-search-parts: Sorting result table by SPN so the output is
consistent.
-rw-r--r-- | src/ee/digikey/__init__.py | 7 | ||||
-rw-r--r-- | src/ee/digikey/search_parts.py | 3 | ||||
-rw-r--r-- | test/test_digikey.py | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index 3eb723e..15eb5e6 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -283,14 +283,13 @@ class DigikeyClient(object): self.cache = ee._utils.maybe_cache(cache_dir) self._driver: Optional[webdriver.Chrome] = None - def search(self, query: str, page_size=10) -> str: - return self.product_search(query, page_size) + def search(self, query: str) -> str: + return self.product_search(query) def _find_first_visible(self, xpath): return next((e for e in self.driver.find_elements_by_xpath(xpath) if e.is_displayed()), None) - def product_search(self, query: str, page_size=10) -> str: - params = {'lang': 'en', 'site': 'us', 'keywords': query, 'pageSize': str(page_size)} + def product_search(self, query: str) -> str: cache_key = urllib.parse.quote(query) cached = self.cache.lookup(cache_key) diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py index e79959a..a1236bb 100644 --- a/src/ee/digikey/search_parts.py +++ b/src/ee/digikey/search_parts.py @@ -94,11 +94,12 @@ class QueryEngine(object): out_part = resolved(self.store.url, response.products[0]) result = "found" elif response.response_type == SearchResponseTypes.MANY: + # TODO: order by spn/mpn so the output is consistent between runs. print("Got many responses:\n", file=self.log) from ee._utils import gen_rst_table - data = [[p.part_number, p.mpn] for p in response.products] + data = [[p.part_number, p.mpn] for p in sorted(response.products, key=lambda x: x.part_number)] print(gen_rst_table(["DK", "MPN"], data), file=self.log) # find those with an exact match. Digikey uses a "contains" search so a query for "FOO" will return "FOO", diff --git a/test/test_digikey.py b/test/test_digikey.py index 4961a9d..cc7dfc7 100644 --- a/test/test_digikey.py +++ b/test/test_digikey.py @@ -48,7 +48,7 @@ def test_digikey_1(tmpdir): @pytest.mark.digikey def test_digikey_2(): - content = client.product_search("TCR2LF", page_size=500) + content = client.product_search("TCR2LF") res = parser.parse_string(client.baseurl, content) assert res.response_type == dk.SearchResponseTypes.MANY |