aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools/digikey_download_facts.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools/digikey_download_facts.py')
-rw-r--r--src/ee/tools/digikey_download_facts.py42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/ee/tools/digikey_download_facts.py b/src/ee/tools/digikey_download_facts.py
index c97ba9d..0550c5f 100644
--- a/src/ee/tools/digikey_download_facts.py
+++ b/src/ee/tools/digikey_download_facts.py
@@ -1,8 +1,6 @@
import argparse
from itertools import *
-import os.path
-import yaml
from colors import color
import ee.digikey as dk
@@ -11,11 +9,6 @@ from ee.tools import mk_parents
parser = argparse.ArgumentParser(description="Download facts about parts from Digi-Key")
-parser.add_argument("parts",
- metavar="PART",
- nargs="+",
- help="The parts to download fact for")
-
parser.add_argument("--out",
required=True,
metavar="OUTPUT_DIRECTORY",
@@ -23,6 +16,12 @@ parser.add_argument("--out",
action="store",
help="A directory to store fact files")
+parser.add_argument("--part",
+ nargs="+",
+ help="the parts to download fact for")
+
+parser.add_argument("--sch")
+
parser.add_argument("--force",
dest="force",
action="store",
@@ -32,26 +31,33 @@ args = parser.parse_args()
digikey = dk.Digikey()
client = dk.DigikeyClient(digikey, on_download=lambda s: print(color(s, 'grey')))
+repo = dk.DigikeyRepository(args.out)
-def mpn_to_path(mpn):
- return "{}/{}.yaml".format(args.out, mpn)
+def on_product(product: DigikeyProduct):
+ repo.save(product)
-def on_product(product: DigikeyProduct):
- y = product.to_yaml()
+parts = []
- filename = mpn_to_path(product.mpn)
- mk_parents(filename)
- with open(filename, "w") as f:
- yaml.dump(y, f, encoding="utf-8", allow_unicode=True)
+if args.part:
+ parts.append(args.part)
+if args.sch:
+ from ee.kicad import read_schematic, to_bom
+ sch = read_schematic(args.sch)
+ for c in to_bom(sch):
+ digikey = c.get_field("digikey")
+ if digikey:
+ parts.append(digikey.value)
+ mpn = c.get_field("mpn")
+ if mpn:
+ parts.append(mpn.value)
-for p in args.parts:
+for p in parts:
print(color("Searching for {}".format(p), "white"))
- path = mpn_to_path(p)
- if os.path.isfile(path) and not args.force:
+ if repo.has_product(p) and not args.force:
continue
response = client.search(p)