diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-07-29 12:05:13 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-07-29 12:05:13 +0200 |
commit | ef5f308dd8d94bf40701c5bb979ad0fe45629ae9 (patch) | |
tree | b115a4bef3174f7d57855a84c05663fa0f8b6617 | |
parent | 4dfe4314efc0a4137899f7a0fce7b653a34219ca (diff) | |
download | ee-python-ef5f308dd8d94bf40701c5bb979ad0fe45629ae9.tar.gz ee-python-ef5f308dd8d94bf40701c5bb979ad0fe45629ae9.tar.bz2 ee-python-ef5f308dd8d94bf40701c5bb979ad0fe45629ae9.tar.xz ee-python-ef5f308dd8d94bf40701c5bb979ad0fe45629ae9.zip |
o Formatting, fixing warnings.
-rw-r--r-- | src/ee/digikey/__init__.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index 3341e28..f607408 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -1,20 +1,21 @@ +import configparser import enum +import glob +import os +import os.path +import re +import urllib.parse +from functools import total_ordering from typing import List, Optional -from ee.tools import mk_parents -import ee._utils -import re import requests -import os -import os.path -import configparser -import glob from cachecontrol import CacheControl from cachecontrol.caches.file_cache import FileCache from cachecontrol.heuristics import ExpiresAfter -from functools import total_ordering from lxml import html -import urllib.parse + +import ee._utils +from ee.tools import mk_parents def normalize_filename(part): @@ -101,13 +102,13 @@ class DigikeyProduct(object): if value: cfg[key] = value - c["overview"] = {}; + c["overview"] = {} overview = c["overview"] overview["part_number"] = self.part_number set(overview, "url", self.url) if self.mpn: overview["mpn"] = self.mpn - c["attributes"] = {}; + c["attributes"] = {} attributes = c["attributes"] for a in self.attributes: key = "{}/{}".format(a.attribute_type.id, a.attribute_type.label) @@ -130,11 +131,11 @@ class DigikeyProduct(object): @staticmethod def from_ini(digikey, c): - def get(c, key): + def get(_c, key): try: - return c[key] + return _c[key] except KeyError: - return None + return None overview = c["overview"] attributes = [] @@ -171,7 +172,7 @@ class DigikeyProductCategory(object): self.digikey_url = digikey_url if digikey_url is None or digikey_url.startswith("http") else \ "https://www.digikey.com" + digikey_url self.parent = parent # type: DigikeyProductCategory - self.subCategories = [] # type: List[DigikeyProductCategory + self.subCategories = [] # type: List[DigikeyProductCategory] assert self.id assert self.label @@ -273,6 +274,7 @@ class DigikeyClient(object): return None + # noinspection PyMethodMayBeStatic def _search_process_multiple_results(self, tree: html, res: DigikeySearchResponse): products = tree.xpath("//*[@itemtype='http://schema.org/Product']") @@ -290,7 +292,7 @@ class DigikeyClient(object): def search(self, query: str, page_size=10) -> DigikeySearchResponse: # http://www.digikey.com/products/en?x=0&y=0&lang=en&site=us&keywords=553-2320-1-ND - params = {'lang': 'en', 'site': 'us', 'keywords': query, 'pageSize': str(page_size), 'x': 0, 'y': 0} + # params = {'lang': 'en', 'site': 'us', 'keywords': query, 'pageSize': str(page_size), 'x': 0, 'y': 0} params = {'lang': 'en', 'site': 'us', 'keywords': query, 'pageSize': str(page_size)} page = self._req("https://www.digikey.com/products/en", params=params) # print("page: ") @@ -352,7 +354,8 @@ class DigikeyRepository(object): def load_all(self): [self._load(path) for path in glob.glob(self._path + "/*.ini")] - def _make_configparser(self): + @staticmethod + def _make_configparser(): c = configparser.ConfigParser() c.optionxform = str return c @@ -377,7 +380,6 @@ class DigikeyRepository(object): def to_pandas(self): import pandas - columns = [] data = [part._to_pandas_dict() for part in self.products] index = [part.mpn for part in self.products] df = pandas.DataFrame(data=data, index=index) |