From f06540f5688dba53cbf9dc0d042cd8e4017d2615 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 8 May 2024 16:51:01 -0500 Subject: [PATCH] Add category field, update datasheet extracted fields --- get_specs.py | 2 ++ read_datasheet.py | 4 ++++ run.py | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/get_specs.py b/get_specs.py index b1c86f3..5eae4c2 100755 --- a/get_specs.py +++ b/get_specs.py @@ -82,6 +82,7 @@ def query_search(partnum, source): desc = a["results"][idx]["raw"]["catalogitemlongdesc"] shortdesc = a["results"][idx]["raw"]["catalogitemshortdesc"] app = a["results"][idx]["raw"]["catalogitemapplication"] + category = a["results"][idx]["raw"]["catalogitemfilterproductcategory"] #a = json.dumps(a["results"][idx], indent=2) #print(a, urlname, img, uri, dsurl) @@ -93,6 +94,7 @@ def query_search(partnum, source): out["short_description"] = shortdesc out["description"] = desc out["application"] = app + out["category"] = category out["image"] = "https://www.belden.com" + img out["partnum"] = name #print(out) diff --git a/read_datasheet.py b/read_datasheet.py index 79dc601..57b1f12 100755 --- a/read_datasheet.py +++ b/read_datasheet.py @@ -387,6 +387,10 @@ def parse(filename, output_dir, partnum, dstype, weburl, extra): output_table["application"] = extra["application"] output_table["fullspecs"]["application"] = extra["application"] output_table["searchspecs"]["application"] = extra["application"] + if "category" in extra: + output_table["category"] = extra["category"] + output_table["fullspecs"]["category"] = extra["category"] + output_table["searchspecs"]["category"] = extra["category"] output_table["searchspecs"]["id"] = id diff --git a/run.py b/run.py index 8831799..f9a4898 100755 --- a/run.py +++ b/run.py @@ -169,29 +169,30 @@ def check_server(): fs = cabledata["fullspecs"] tmp1 = {"part_number": cable_list[idx], "position": idx, "name": cable_list[idx], "brand": cabledata["brand"] } if "Product Overview" in fs and "Product Category" in fs["Product Overview"]: - tmp1["short_description"] = fs["Product Overview"]["Product Category"] + tmp1["category"] = fs["Product Overview"]["Product Category"] if "Product Overview" in fs and "Suitable Applications" in fs["Product Overview"]: if len(fs["Product Overview"]["Suitable Applications"]) == 0 or not isinstance(fs["Product Overview"]["Suitable Applications"], str): print(cable_list[idx], fs["Product Overview"]["Suitable Applications"]) for key, value in fs["Product Overview"].items(): #print(key,value) if len(value) > 5 and isinstance(value, str): - tmp1["description"] = value + tmp1["application"] = value elif len(key) > 15 and not isinstance(value, str): - tmp1["description"] = key + tmp1["application"] = key else: - tmp1["description"] = fs["Product Overview"]["Suitable Applications"] + tmp1["application"] = fs["Product Overview"]["Suitable Applications"] elif "Product Overview" in fs and "Suitable Applications:" in fs["Product Overview"]: if len(fs["Product Overview"]["Suitable Applications:"]) == 0 or not isinstance(fs["Product Overview"]["Suitable Applications:"], str): print(cable_list[idx], fs["Product Overview"]["Suitable Applications:"]) for key, value in fs["Product Overview"].items(): #print(key,value) if len(value) > 5 and isinstance(value, str): - tmp1["description"] = value + tmp1["application"] = value elif len(key) > 15 and not isinstance(value, str): - tmp1["description"] = key + tmp1["application"] = key else: - tmp1["description"] = fs["Product Overview"]["Suitable Applications:"] + tmp1["application"] = fs["Product Overview"]["Suitable Applications:"] + if "image" in cabledata: tmp1["image"] = cabledata["image"] if "description" in cabledata: @@ -200,7 +201,9 @@ def check_server(): tmp1["short_description"] = cabledata["short_description"] if "application" in cabledata: tmp1["application"] = cabledata["application"] - + if "category" in cabledata: + tmp1["category"] = cabledata["category"] + tmp.append(tmp1) out = {"map": tmp} fprint(out)