diff options
| author | Trygve Laugstøl <trygvis@inamo.no> | 2017-09-24 09:46:21 +0200 | 
|---|---|---|
| committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-09-24 09:46:21 +0200 | 
| commit | 930e3d61917bd4bf162142db64301691afdf9539 (patch) | |
| tree | f2e06b6aef12026a5f99742ca78f178f63f5037b /src/ee/digikey | |
| parent | 33a03ca8cb65202509bd009832010f8f587ace47 (diff) | |
| download | ee-python-930e3d61917bd4bf162142db64301691afdf9539.tar.gz ee-python-930e3d61917bd4bf162142db64301691afdf9539.tar.bz2 ee-python-930e3d61917bd4bf162142db64301691afdf9539.tar.xz ee-python-930e3d61917bd4bf162142db64301691afdf9539.zip | |
o Let digikey-download-facts read .sch files directly.
Diffstat (limited to 'src/ee/digikey')
| -rw-r--r-- | src/ee/digikey/__init__.py | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index 64d8943..af5977b 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -1,8 +1,12 @@  import enum  from typing import List, Optional +from ee.tools import mk_parents  import re  import requests +import os +import os.path +import yaml  from cachecontrol import CacheControl  from cachecontrol.caches.file_cache import FileCache  from cachecontrol.heuristics import ExpiresAfter @@ -266,3 +270,21 @@ class DigikeyClient(object):                  return res              else:                  return DigikeySearchResponse(1, SearchResponseTypes.NO_MATCHES) + +class DigikeyRepository(object): +    def __init__(self, path): +        self._path = path + +    def mpn_to_path(self, mpn): +        return "{}/{}.yaml".format(self._path, mpn) + +    def has_product(self, mpn): +        filename = self.mpn_to_path(mpn) +        return os.path.isfile(filename) + +    def save(self, product: DigikeyProduct): +        y = product.to_yaml() +        filename = self.mpn_to_path(product.mpn) +        mk_parents(filename) +        with open(filename, "w") as f: +            yaml.dump(y, f, encoding="utf-8", allow_unicode=True) | 
