From 930e3d61917bd4bf162142db64301691afdf9539 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 24 Sep 2017 09:46:21 +0200 Subject: o Let digikey-download-facts read .sch files directly. --- src/ee/digikey/__init__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/ee/digikey') 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) -- cgit v1.2.3