diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-08-15 13:30:19 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-08-15 13:30:19 +0200 |
commit | c4a1a452d344de0ee45e2fb2c8284c636eb05818 (patch) | |
tree | 753e6856ac03f58a3835bbfdea3d9e2265ccf45b /src/ee/digikey | |
parent | 8c4ec1bd2e1d63c4c5898826fdbcce08417f85b6 (diff) | |
download | ee-python-c4a1a452d344de0ee45e2fb2c8284c636eb05818.tar.gz ee-python-c4a1a452d344de0ee45e2fb2c8284c636eb05818.tar.bz2 ee-python-c4a1a452d344de0ee45e2fb2c8284c636eb05818.tar.xz ee-python-c4a1a452d344de0ee45e2fb2c8284c636eb05818.zip |
digikey-search-parts: Adding summary in download report.
Diffstat (limited to 'src/ee/digikey')
-rw-r--r-- | src/ee/digikey/search_parts.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py index c0da731..703e65f 100644 --- a/src/ee/digikey/search_parts.py +++ b/src/ee/digikey/search_parts.py @@ -80,7 +80,7 @@ class QueryEngine(object): def pn_spn_search(self, pn, is_spn): s = "Searching for '{}'".format(pn) print(s, file=self.log) - print("=" * len(s) + "\n", file=self.log) + print("-" * len(s) + "\n", file=self.log) out_part = None result = None @@ -220,24 +220,52 @@ def run_search_parts(in_path: Path, out_path: Path, log, cache_dir: Path, store_ pn_queries = list(sorted(pn_qs)) spn_queries = list(sorted(spn_qs)) - print("Executing {} manufacturer product number searches\n\n".format(len(pn_queries)), file=log) + s = "Manufacturer product number searches" + print("{}\n{}\n".format(s, "=" * len(s)), file=log) + print("Executing {} manufacturer product number searches:\n\n".format(len(pn_queries)), file=log) exception = False + mpn_results = {} for q in pn_queries: res = engine.pn_search(q.pn) + + if res in mpn_results: + mpn_results[res] = mpn_results[res] + 1 + else: + mpn_results[res] = 1 + if res == SearchResponseTypes.EXCEPTION: exception = True break + spn_results = {} if not exception: - print("Executing {} supplier product number searches\n\n".format(len(spn_queries)), file=log) + if len(spn_queries) == 0: + print("Executing no supplier product number searches.\n\n".format(len(spn_queries)), file=log) + else: + print("Executing {} supplier product number searches:\n\n".format(len(spn_queries)), file=log) for q in spn_queries: res = engine.spn_search(q.spn) + + if res in spn_results: + spn_results[res] = spn_results[res] + 1 + else: + spn_results[res] = 1 + if res == SearchResponseTypes.EXCEPTION: exception = True break + header = "Statistics" + print("{}\n{}\n".format(header, "=" * len(header)), file=log) + + for name, results in [("MPN", mpn_results), ("SPN", spn_results)]: + print("{} Searches:\n".format(name), file=log) + for res, count in results.items(): + print("* {}: {}".format(res.name, count), file=log) + print("", file=log) + part_db = PartDb() for part in engine.out_parts: part_db.add_entry(part, True) |