aboutsummaryrefslogtreecommitdiff
path: root/trygvis/eda/cli/digikey_download_attribute_types_for_category.py
diff options
context:
space:
mode:
Diffstat (limited to 'trygvis/eda/cli/digikey_download_attribute_types_for_category.py')
-rw-r--r--trygvis/eda/cli/digikey_download_attribute_types_for_category.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/trygvis/eda/cli/digikey_download_attribute_types_for_category.py b/trygvis/eda/cli/digikey_download_attribute_types_for_category.py
new file mode 100644
index 0000000..aef360c
--- /dev/null
+++ b/trygvis/eda/cli/digikey_download_attribute_types_for_category.py
@@ -0,0 +1,29 @@
+from trygvis.eda import cli, write_graph
+
+from trygvis.eda.digikey import *
+
+
+def run(category, sub_category, output_file, args):
+ client = DigikeyClient()
+ db = DigikeyDatabase()
+
+ download_category_tree(db, client)
+ c = db.find_category(category)
+
+ if c is None:
+ cli.exit("Could not find category \"%s\"" % category)
+
+ sc = c.find_sub_category_by_label(sub_category)
+
+ if c is None:
+ cli.exit("Could not find sub-category \"%s\" inside \"%s\"" % (sub_category, category))
+
+ attributes = download_attribute_types_from_category(sc, client)
+ db.merge_attribute_types(attributes)
+
+ g = cli.create_graph()
+ for a in attributes:
+ [g.add(node) for node in a.to_nodes()]
+
+ filename = output_file if output_file is not "-" else None
+ write_graph(gen_g=lambda: g, filename=filename)