From 2e2956823c9cd02c766b296cbcbea9130bd07b36 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 28 May 2019 09:46:41 +0200 Subject: digikey: Better search when getting multiple results back. Instead of doing a new search with the selected digikey part number, do a direct lookup with the product's URL instead. This ensures that we always get a match and don't get confused when multiple part numbers are returned. --- src/ee/_utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/ee/_utils.py') diff --git a/src/ee/_utils.py b/src/ee/_utils.py index 08e75fa..5960161 100644 --- a/src/ee/_utils.py +++ b/src/ee/_utils.py @@ -77,3 +77,24 @@ class EmptyHttpCache(object): def maybe_cache(path: Optional[Path], **kwargs) -> HttpCache: return HttpCache(path, **kwargs) if path is not None else EmptyHttpCache() + + +def gen_rst_table(header: List[str], data: List[List[str]]): + column_widths = [] + for i in range(len(header)): + w = len(header[i]) + for row in data: + w = max(w, len(row[i])) + column_widths.append(w) + + import io + buf = io.StringIO() + sep = "+-" + "-+-".join(["-" * w for i, w in enumerate(column_widths)]) + "-+" + print(sep, file=buf) + print("| " + " | ".join([header[i].ljust(w) for i, w in enumerate(column_widths)]) + " |", file=buf) + print(sep.replace("-", "="), file=buf) + for row in data: + print("| " + " | ".join([row[i].ljust(w) for i, w in enumerate(column_widths)]) + " |", file=buf) + print(sep, file=buf) + + return buf.getvalue() -- cgit v1.2.3